Usar mesmo módulo em várias planilhas

Anônima
2021-11-10T21:35:01+00:00

Olá. Fiz uma macro que prrenche a cor de uma célula de acordo com os valores RGB contidos em outras células. Acontece que essa macro só roda na Planilha 1, e gostaria que ela rodasse em qualquer planílha que fosse chamada. Alqgué pode me ajudar? Segue o código:

Desde já agradeço

Dim Red As Integer

Dim Green As Integer

Dim Blue As Integer

Sub AddColor()

'BA123 resultante 1

Red = Planilha1.Cells(23, 5).Value

Green = Planilha1.Cells(24, 5).Value

Blue = Planilha1.Cells(25, 5).Value

Cells(21, 9).Interior.Color = RGB(Red, Green, Blue)

'BA4 resultante 1

Red = Planilha1.Cells(33, 5).Value

Green = Planilha1.Cells(34, 5).Value

Blue = Planilha1.Cells(35, 5).Value

Cells(31, 9).Interior.Color = RGB(Red, Green, Blue)

'BA5 resultante 1

Red = Planilha1.Cells(43, 5).Value

Green = Planilha1.Cells(44, 5).Value

Blue = Planilha1.Cells(45, 5).Value

Cells(41, 9).Interior.Color = RGB(Red, Green, Blue)

'BA6 resultante 1

Red = Planilha1.Cells(53, 5).Value

Green = Planilha1.Cells(54, 5).Value

Blue = Planilha1.Cells(55, 5).Value

Cells(51, 9).Interior.Color = RGB(Red, Green, Blue)

'BA7 resultante 1

Red = Planilha1.Cells(63, 5).Value

Green = Planilha1.Cells(64, 5).Value

Blue = Planilha1.Cells(65, 5).Value

Cells(61, 9).Interior.Color = RGB(Red, Green, Blue)

'BA8 resultante 1

Red = Planilha1.Cells(73, 5).Value

Green = Planilha1.Cells(74, 5).Value

Blue = Planilha1.Cells(75, 5).Value

Cells(71, 9).Interior.Color = RGB(Red, Green, Blue)

'BA9 resultante 1

Red = Planilha1.Cells(83, 5).Value

Green = Planilha1.Cells(84, 5).Value

Blue = Planilha1.Cells(85, 5).Value

Cells(81, 9).Interior.Color = RGB(Red, Green, Blue)

'BA10 resultante 1

Red = Planilha1.Cells(93, 5).Value

Green = Planilha1.Cells(94, 5).Value

Blue = Planilha1.Cells(95, 5).Value

Cells(91, 9).Interior.Color = RGB(Red, Green, Blue)

'B11 resultante 1

Red = Planilha1.Cells(103, 5).Value

Green = Planilha1.Cells(104, 5).Value

Blue = Planilha1.Cells(105, 5).Value

Cells(101, 9).Interior.Color = RGB(Red, Green, Blue)

'BA17 resultante 1

Red = Planilha1.Cells(113, 5).Value

Green = Planilha1.Cells(114, 5).Value

Blue = Planilha1.Cells(115, 5).Value

Cells(111, 9).Interior.Color = RGB(Red, Green, Blue)

'BA18 resultante 1

Red = Planilha1.Cells(123, 5).Value

Green = Planilha1.Cells(124, 5).Value

Blue = Planilha1.Cells(125, 5).Value

Cells(121, 9).Interior.Color = RGB(Red, Green, Blue)

'BA19 resultante 1

Red = Planilha1.Cells(133, 5).Value

Green = Planilha1.Cells(134, 5).Value

Blue = Planilha1.Cells(135, 5).Value

Cells(131, 9).Interior.Color = RGB(Red, Green, Blue)

'BA20 resultante 1

Red = Planilha1.Cells(143, 5).Value

Green = Planilha1.Cells(144, 5).Value

Blue = Planilha1.Cells(145, 5).Value

Cells(141, 9).Interior.Color = RGB(Red, Green, Blue)

'BA21 resultante 1

Red = Planilha1.Cells(153, 5).Value

Green = Planilha1.Cells(154, 5).Value

Blue = Planilha1.Cells(155, 5).Value

Cells(151, 9).Interior.Color = RGB(Red, Green, Blue)

'BA22 resultante 1

Red = Planilha1.Cells(163, 5).Value

Green = Planilha1.Cells(164, 5).Value

Blue = Planilha1.Cells(165, 5).Value

Cells(161, 9).Interior.Color = RGB(Red, Green, Blue)

'BA37 resultante 1

Red = Planilha1.Cells(173, 5).Value

Green = Planilha1.Cells(174, 5).Value

Blue = Planilha1.Cells(175, 5).Value

Cells(171, 9).Interior.Color = RGB(Red, Green, Blue)

'BA38 resultante 1

Red = Planilha1.Cells(183, 5).Value

Green = Planilha1.Cells(184, 5).Value

Blue = Planilha1.Cells(185, 5).Value

Cells(181, 9).Interior.Color = RGB(Red, Green, Blue)

'BA39 resultante 1

Red = Planilha1.Cells(193, 5).Value

Green = Planilha1.Cells(194, 5).Value

Blue = Planilha1.Cells(195, 5).Value

Cells(191, 9).Interior.Color = RGB(Red, Green, Blue)

'BA40 resultante 1

Red = Planilha1.Cells(203, 5).Value

Green = Planilha1.Cells(204, 5).Value

Blue = Planilha1.Cells(205, 5).Value

Cells(201, 9).Interior.Color = RGB(Red, Green, Blue)

'BA41 resultante 1

Red = Planilha1.Cells(213, 5).Value

Green = Planilha1.Cells(214, 5).Value

Blue = Planilha1.Cells(215, 5).Value

Cells(211, 9).Interior.Color = RGB(Red, Green, Blue)

'BA42 resultante 1

Red = Planilha1.Cells(223, 5).Value

Green = Planilha1.Cells(224, 5).Value

Blue = Planilha1.Cells(225, 5).Value

Cells(221, 9).Interior.Color = RGB(Red, Green, Blue)

'BA43 resultante 1

Red = Planilha1.Cells(233, 5).Value

Green = Planilha1.Cells(234, 5).Value

Blue = Planilha1.Cells(235, 5).Value

Cells(231, 9).Interior.Color = RGB(Red, Green, Blue)

'BA44 resultante 1

Red = Planilha1.Cells(243, 5).Value

Green = Planilha1.Cells(244, 5).Value

Blue = Planilha1.Cells(245, 5).Value

Cells(241, 9).Interior.Color = RGB(Red, Green, Blue)

'BA45 resultante 1

Red = Planilha1.Cells(253, 5).Value

Green = Planilha1.Cells(254, 5).Value

Blue = Planilha1.Cells(255, 5).Value

Cells(251, 9).Interior.Color = RGB(Red, Green, Blue)

'BA46 resultante 1

Red = Planilha1.Cells(263, 5).Value

Green = Planilha1.Cells(264, 5).Value

Blue = Planilha1.Cells(265, 5).Value

Cells(261, 9).Interior.Color = RGB(Red, Green, Blue)

'BA47 resultante 1

Red = Planilha1.Cells(273, 5).Value

Green = Planilha1.Cells(274, 5).Value

Blue = Planilha1.Cells(275, 5).Value

Cells(271, 9).Interior.Color = RGB(Red, Green, Blue)

'BAcerebelo resultante 1

Red = Planilha1.Cells(283, 5).Value

Green = Planilha1.Cells(284, 5).Value

Blue = Planilha1.Cells(285, 5).Value

Cells(281, 9).Interior.Color = RGB(Red, Green, Blue)

'BAinsula resultante 1

Red = Planilha1.Cells(293, 5).Value

Green = Planilha1.Cells(294, 5).Value

Blue = Planilha1.Cells(295, 5).Value

Cells(291, 9).Interior.Color = RGB(Red, Green, Blue)

'--------------------------------------

'--------------------------------------

'BA123 resultante 2

Red = Planilha1.Cells(23, 15).Value

Green = Planilha1.Cells(24, 15).Value

Blue = Planilha1.Cells(25, 15).Value

Cells(21, 19).Interior.Color = RGB(Red, Green, Blue)

'BA4 resultante 2

Red = Planilha1.Cells(33, 15).Value

Green = Planilha1.Cells(34, 15).Value

Blue = Planilha1.Cells(35, 15).Value

Cells(31, 19).Interior.Color = RGB(Red, Green, Blue)

'BA5 resultante 2

Red = Planilha1.Cells(43, 15).Value

Green = Planilha1.Cells(44, 15).Value

Blue = Planilha1.Cells(45, 15).Value

Cells(41, 19).Interior.Color = RGB(Red, Green, Blue)

'BA6 resultante 2

Red = Planilha1.Cells(53, 15).Value

Green = Planilha1.Cells(54, 15).Value

Blue = Planilha1.Cells(55, 15).Value

Cells(51, 19).Interior.Color = RGB(Red, Green, Blue)

'BA7 resultante 2

Red = Planilha1.Cells(63, 15).Value

Green = Planilha1.Cells(64, 15).Value

Blue = Planilha1.Cells(65, 15).Value

Cells(61, 19).Interior.Color = RGB(Red, Green, Blue)

'BA8 resultante 2

Red = Planilha1.Cells(73, 15).Value

Green = Planilha1.Cells(74, 15).Value

Blue = Planilha1.Cells(75, 15).Value

Cells(71, 19).Interior.Color = RGB(Red, Green, Blue)

'BA9 resultante 2

Red = Planilha1.Cells(83, 15).Value

Green = Planilha1.Cells(84, 15).Value

Blue = Planilha1.Cells(85, 15).Value

Cells(81, 19).Interior.Color = RGB(Red, Green, Blue)

'BA10 resultante 2

Red = Planilha1.Cells(93, 15).Value

Green = Planilha1.Cells(94, 15).Value

Blue = Planilha1.Cells(95, 15).Value

Cells(91, 19).Interior.Color = RGB(Red, Green, Blue)

'B11 resultante 2

Red = Planilha1.Cells(103, 15).Value

Green = Planilha1.Cells(104, 15).Value

Blue = Planilha1.Cells(105, 15).Value

Cells(101, 19).Interior.Color = RGB(Red, Green, Blue)

'BA17 resultante 2

Red = Planilha1.Cells(113, 15).Value

Green = Planilha1.Cells(114, 15).Value

Blue = Planilha1.Cells(115, 15).Value

Cells(111, 19).Interior.Color = RGB(Red, Green, Blue)

'BA18 resultante 2

Red = Planilha1.Cells(123, 15).Value

Green = Planilha1.Cells(124, 15).Value

Blue = Planilha1.Cells(125, 15).Value

Cells(121, 19).Interior.Color = RGB(Red, Green, Blue)

'BA19 resultante 2

Red = Planilha1.Cells(133, 15).Value

Green = Planilha1.Cells(134, 15).Value

Blue = Planilha1.Cells(135, 15).Value

Cells(131, 19).Interior.Color = RGB(Red, Green, Blue)

'BA20 resultante 2

Red = Planilha1.Cells(143, 15).Value

Green = Planilha1.Cells(144, 15).Value

Blue = Planilha1.Cells(145, 15).Value

Cells(141, 19).Interior.Color = RGB(Red, Green, Blue)

'BA21 resultante 2

Red = Planilha1.Cells(153, 15).Value

Green = Planilha1.Cells(154, 15).Value

Blue = Planilha1.Cells(155, 15).Value

Cells(151, 19).Interior.Color = RGB(Red, Green, Blue)

'BA22 resultante 2

Red = Planilha1.Cells(163, 15).Value

Green = Planilha1.Cells(164, 15).Value

Blue = Planilha1.Cells(165, 15).Value

Cells(161, 19).Interior.Color = RGB(Red, Green, Blue)

'BA37 resultante 2

Red = Planilha1.Cells(173, 15).Value

Green = Planilha1.Cells(174, 15).Value

Blue = Planilha1.Cells(175, 15).Value

Cells(171, 19).Interior.Color = RGB(Red, Green, Blue)

'BA38 resultante 2

Red = Planilha1.Cells(183, 15).Value

Green = Planilha1.Cells(184, 15).Value

Blue = Planilha1.Cells(185, 15).Value

Cells(181, 19).Interior.Color = RGB(Red, Green, Blue)

'BA39 resultante 2

Red = Planilha1.Cells(193, 15).Value

Green = Planilha1.Cells(194, 15).Value

Blue = Planilha1.Cells(195, 15).Value

Cells(191, 19).Interior.Color = RGB(Red, Green, Blue)

'BA40 resultante 2

Red = Planilha1.Cells(203, 15).Value

Green = Planilha1.Cells(204, 15).Value

Blue = Planilha1.Cells(205, 15).Value

Cells(201, 19).Interior.Color = RGB(Red, Green, Blue)

'BA41 resultante 2

Red = Planilha1.Cells(213, 15).Value

Green = Planilha1.Cells(214, 15).Value

Blue = Planilha1.Cells(215, 15).Value

Cells(211, 19).Interior.Color = RGB(Red, Green, Blue)

'BA42 resultante 2

Red = Planilha1.Cells(223, 15).Value

Green = Planilha1.Cells(224, 15).Value

Blue = Planilha1.Cells(225, 15).Value

Cells(221, 19).Interior.Color = RGB(Red, Green, Blue)

'BA43 resultante 2

Red = Planilha1.Cells(233, 15).Value

Green = Planilha1.Cells(234, 15).Value

Blue = Planilha1.Cells(235, 15).Value

Cells(231, 19).Interior.Color = RGB(Red, Green, Blue)

'BA44 resultante 2

Red = Planilha1.Cells(243, 15).Value

Green = Planilha1.Cells(244, 15).Value

Blue = Planilha1.Cells(245, 15).Value

Cells(241, 19).Interior.Color = RGB(Red, Green, Blue)

'BA45 resultante 2

Red = Planilha1.Cells(253, 15).Value

Green = Planilha1.Cells(254, 15).Value

Blue = Planilha1.Cells(255, 15).Value

Cells(251, 19).Interior.Color = RGB(Red, Green, Blue)

'BA46 resultante 2

Red = Planilha1.Cells(263, 15).Value

Green = Planilha1.Cells(264, 15).Value

Blue = Planilha1.Cells(265, 15).Value

Cells(261, 19).Interior.Color = RGB(Red, Green, Blue)

'BA47 resultante 2

Red = Planilha1.Cells(273, 15).Value

Green = Planilha1.Cells(274, 15).Value

Blue = Planilha1.Cells(275, 15).Value

Cells(271, 19).Interior.Color = RGB(Red, Green, Blue)

'BAcerebelo resultante 2

Red = Planilha1.Cells(283, 15).Value

Green = Planilha1.Cells(284, 15).Value

Blue = Planilha1.Cells(285, 15).Value

Cells(281, 19).Interior.Color = RGB(Red, Green, Blue)

'BAinsula resultante 2

Red = Planilha1.Cells(293, 15).Value

Green = Planilha1.Cells(294, 15).Value

Blue = Planilha1.Cells(295, 15).Value

Cells(291, 19).Interior.Color = RGB(Red, Green, Blue)

End Sub

Microsoft 365 e Office | Excel | Para uso doméstico | Windows

Pergunta bloqueada. Essa pergunta foi migrada da Comunidade de Suporte da Microsoft. É possível votar se é útil, mas não é possível adicionar comentários ou respostas ou seguir a pergunta.

0 comentários Sem comentários

2 respostas

Classificar por: Mais útil
  1. Anônima
    2021-11-12T21:45:40+00:00

    Opa Túlio, BLZ?

    Creio que seja só trocar todos os locais onde possuem "planilha1" por "worksheet"

    se possível, me responda se deu certo

    Consegui.

    apenas tirei a referência à planilha.

    valeu mesmo

    Esta resposta foi útil?

    0 comentários Sem comentários
  2. Anônima
    2021-11-11T01:05:15+00:00

    Opa Túlio, BLZ?

    Creio que seja só trocar todos os locais onde possuem "planilha1" por "worksheet"

    se possível, me responda se deu certo

    Esta resposta foi útil?

    0 comentários Sem comentários