Make VBA codes according to one specific sheet and not all entire workbook?

Lacan

Board Regular
Joined
Oct 5, 2016
Messages
228
Office Version
  1. 365
Platform
  1. Windows
Hi Guys, 😉👍

Hope all of you are fine!👌🍻
Would like your help in this question:

Have this 3 different codes below that work very fine but would like to use them in one specific sheet and not all entire workbook?
What kind of changes have to add in each one code?


VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C20")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Cells(20, 2).Value = Format(Date, "dd-mmm")
End If
End Sub

-----------------------------------------
VBA Code:
Sub Linha()
'
' Linha Macro
'

'
    Rows("24:24").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("C24:S24").Select
    With Selection
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
    With Selection
        .Font.Bold = True
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = True
    End With
    With Selection.Font
        .Color = -65536
        .TintAndShade = 0
    End With
    Range("C24:S24").Select
End Sub

Sub Novo()
'
' Novo Macro
'

'
    Rows("20:25").Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("B20").Select
    Selection.NumberFormat = "dd-mmm"
    Range("B24").Select
    ActiveCell.FormulaR1C1 = "OBJECTIVO"
    Range("C20:S20").Select
    With Selection
        .Font.Bold = True
        .HorizontalAlignment = xlCenter
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Selection.Merge
    With Selection
        .Font.Bold = True
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = True
    End With
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    Selection.Borders(xlEdgeLeft).LineStyle = xlNone
    Selection.Borders(xlEdgeTop).LineStyle = xlNone
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .ColorIndex = 0
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlEdgeRight).LineStyle = xlNone
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    Selection.AutoFill Destination:=Range("C20:S24"), Type:=xlFillDefault
    Range("C20:S24").Select
    Range("B20:B24").Select
    With Selection
        .HorizontalAlignment = xlLeft
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
    Range("B20:S24").Select
    With Selection.Font
        .Name = "Calibri"
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ThemeColor = xlThemeColorLight1
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
    With Selection.Font
        .Color = -65536
        .TintAndShade = 0
    End With
    Range("C20:S24").Select
End Sub

Customer File.xlsb
ABCDEFGHIJKLMNOPQRST
1
2BioUn. Tipo
3RANK
4Coordenador
5Limpezas
6Horário de Visita
7Observações
8
9N.º
10
11
12
13
14
15
16
17
18
19ANOTE O QUE DE RELEVANTE ACONTECEU NA PRESENTE ENTREVISTA E ESCREVA A FORMA COMO VAI COMEÇAR A PRÓXIMA ENTREVISTA DE VENDAS.
20
21
22
23
24OBJECTIVO
25
26
ORGANIZATION
Cells with Data Validation
CellAllowCriteria
B2List=#REF!$A$3#
C2:G2Any value
 
I am afraid I don't understand your question
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I am afraid I don't understand your question

Dear @MARK858

Lets try again!👌
Have a conflict with 2 VBA´s code wich gets an error.
To explain:

1728206633421.png



This one Code below changes the name of the sheet accordingly with the name written in cell B2 (after press Buton "Enter") in Sheet "NOME INSTITUIÇÃO":

Sub Enter()
ActiveSheet.Name = Range("B2").Value
End Sub


And this second code below combined with Sheet´s name "NOME INSTITUIÇÃO" doesn´t match because early this sheet´s name has been changed previously code one.

Private Sub Worksheet_Change(ByVal Target As Range)

Sheets("NOME INSTITUIÇÃO").Activate

If Not Intersect(Target, Range("C22")) Is Nothing Then
If Target.Cells.Count > 1 Or IsEmpty(Target) Then Exit Sub
Cells(22, 2).Value = Format(Date, "dd-mmm")
End If
End Sub


Can you help or should make a new thread?
Thanks again for all the help!👍👍🍻
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,511
Members
452,194
Latest member
Lowie27

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top