font and background color

Status
Not open for further replies.

prw79

New Member
Joined
Aug 5, 2022
Messages
18
Office Version
  1. 2019
Platform
  1. Windows
The following code will takeover the font colors of the names from the original list into my dropdownlist. 2 questions: how can i also do this with the background (fill) color? 2nd question: When i delete a name from the dropdown list an error occurs: 'Run-time error 91: Object variable or With block variable not set'
code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("B2:B32")) Is Nothing Then Exit Sub
With Target.Font
.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Color
.Bold = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Bold
End With
End Sub


Hope someone can help? thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Value = "" Then Exit Sub
   If Not Intersect(Target, Range("B2:B32")) Is Nothing Then
      With Target
         .Interior.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Interior.Color
         .Font.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Color
         .Font.Bold = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Bold
      End With
   End If
End Sub
 
Upvote 0
Solution
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Value = "" Then Exit Sub
   If Not Intersect(Target, Range("B2:B32")) Is Nothing Then
      With Target
         .Interior.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Interior.Color
         .Font.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Color
         .Font.Bold = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Bold
      End With
   End If
End Sub
That is amazing! thanks a bunch
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Value = "" Then Exit Sub
   If Not Intersect(Target, Range("B2:B32")) Is Nothing Then
      With Target
         .Interior.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Interior.Color
         .Font.Color = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Color
         .Font.Bold = Sheets("Maandoverzicht").Range("B8:B31").Find(Target).Font.Bold
      End With
   End If
End Sub
for a follow up question: How can i add more sheets and ranges within the same code? hope you can help.
 
Upvote 0
for a follow up question: How can i add more sheets and ranges within the same code? hope you can help.
You already posted that question to a new thread here: target as range

Per forum rules, please do NOT duplicate the same question in multiple threads. Such posts will typically be locked or deleted.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,093
Latest member
dbomb1414

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