Hi! I would like ask, how possible do in VBA highlight row if specific cell not empty.
For example i have numbers in "A" column 1,2,3,4,5 and if have value next to 1,3 and 5 in "B" column like: 1 | a , 3 | b, 5 | c highlight this 3 row from "A" to "C".
VBA row highlight if specific cell not empty
- zsolti90
- Thread is marked as Resolved.
-
-
Hello,
Much better than a description which is always difficult to clearly explain ...
Why don't you attach a sample file ...
-
Yes you right about it, so i have 2 files. The first name always fix, but the second file always change, i wouldnt like change in code each time when i want run the macro.
In 1.xlsx file have lot of lines, if i have same line in 2.xlsx i would like highlight, -
Re,
If my understanding is correct ...
Attached is your test file
Hope this will help
-
Thank you very much your help! I have just one problem. Later i have to use the 2.xlx file to run script in other app, thats why sadly i can not change the format to .xlsm from .xlsx. Possible to do it from 1.xlsx? Its really big help for me!
Sorry i forget said to you 2 more things. Can be couple of thousand line, and in 2.xlsx file can be lines with value in "C" whoch different than 1.xlsx. -
-
Re,
Not sure what you mean by ' to do it from 1.xlsx ' ...
Do you already have macros in 1.xlsx ... which should be 1.xlsm ... ?
Is your file 2.xlsx generated by 1.xlsx ...?
Are you working with opened or closed files ...?
-
In 1.xlsx i have a massive list which is couple of thousand lines. In 2.xlsx file i have like 5-10 or sometimes 30 lines. So i put the value from 1.xlsx to 2.xlsx, after than i would like highlight the row where is the new value.
Yes i have macro in 1.xlsx, which automatic put the value from 1.xlsx to 2.xlsx, but i would like highlight as well. So yes the 1. file form is 1.xlsm, but i can put other button wich highlight button and its can highlight in 2.xlsx file row.
2.xlsx file we create this, we put same number from email, and after we have search in 1.xlsx file the value for number, but this part done with macro, i would like just highlight this rows.
I work with opened files. I hope i explain to you everything. Thank you your help! -
Quote
Yes i have macro in 1.xlsx, which automatic put the value from 1.xlsx to 2.xlsx
Just two questions :
1. Why not modifying the macro you already have to Add the Color ...?
2. Why aren't you posting the macro you have ...?
-
I did try change the macro but the highlight not work very well, because this code highlight the empty cell as well. Please see below my code:
Code
Display MoreOption Explicit Function getFile() As Workbook Dim fn As Variant fn = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*), *.xls*", Title:="Select workbook") If TypeName(fn) <> "Boolean" Then Set getFile = Workbooks.Open(fn) End Function Sub useGetFile() Dim Dic As Object Dim key As Variant Dim oCell As Range Dim i As Long Dim wb1 As Workbook, wb2 As Workbook Dim ws1 As Worksheet, ws2 As Worksheet Set Dic = CreateObject("Scripting.Dictionary") Set wb2 = getFile If Not wb2 Is Nothing Then On Error Resume Next Set ws2 = wb2.Sheets("Sheet1") On Error GoTo 0 If Not ws2 Is Nothing Then Set wb1 = Workbooks("1.xlsx") Set ws1 = wb1.Sheets("Sheet1") i = ws1.Cells.SpecialCells(xlCellTypeLastCell).Row For Each oCell In ws1.Range("A1:A" & i) If Not Dic.exists(oCell.Value) Then Dic.Add oCell.Value, oCell.Offset(, 3).Value End If Next i = ws2.Cells.SpecialCells(xlCellTypeLastCell).Row For Each oCell In ws2.Range("A2:A" & i) For Each key In Dic If oCell.Value = key Then oCell.Offset(, 3).Value = Dic(key) oCell.Offset(, 0).Interior.ColorIndex = 37 oCell.Offset(, 1).Interior.ColorIndex = 37 oCell.Offset(, 2).Interior.ColorIndex = 37 oCell.Offset(, 3).Interior.ColorIndex = 37 oCell.Offset(, 4).Interior.ColorIndex = 37 oCell.Offset(, 5).Interior.ColorIndex = 37 oCell.Offset(, 6).Interior.ColorIndex = 37 oCell.Offset(, 7).Interior.ColorIndex = 37 End If Next Next Else MsgBox "Sheet1 not found in " & wb2.Name, vbCritical End If 'Maybe close wb2 here? 'wb2.Close SaveChanges:=False Else Debug.Print "User cancelled" End If Set wb1 = Nothing Set wb2 = Nothing Set ws1 = Nothing Set ws2 = Nothing Set Dic = Nothing End Sub
-
Re,
Your explanations are very confusing ...
You could test following instructions to replace your lines 34 to 54
-
-
I did try test it, but i got "For control variable already in use error"
-
Re,
To be tested from workbook 1 ...
Code
Display MoreSub AddColor() Dim c As Range, rng As Range Dim last As Long Dim wb2 As Workbook, ws2 As Worksheet Set wb2 = Workbooks("2.xlsx") Set ws2 = wb2.Sheets("Sheet1") last = ws2.Cells(Rows.Count, 1).End(xlUp).Row ws2.Range("A1:D" & last).Interior.Color = xlNone Set rng = ws2.Range("C1:C" & last) For Each c In rng If Not IsEmpty(c) Then ws2.Range(Cells(c.Row, 1), Cells(c.Row, 7)).Interior.Color = RGB(146, 208, 80) End If Next c End Sub
-
Re,
Very surprising ...!!!
Make sure what you are calling ' empty cells ' ... ARE indeed EMPTY cells ...
-
I should integrate this to my code, but the problem is for me thsi code not work, and you have fix file name for 2.xlsx.
I try run run jsut this code but nothing happen. I dont know where is the problem because i didnt got any errors. -
What has happened to your message # 13 ... ???
-
-
I deleted it, because i tried use with other code. So that message nothing mean now.
-
Why not use Conditional Formatting without VBA?
-
Is it possible to do something, if i have value in C:10 highlight this row?
-
Can you attach a small example workbook
-
yes sure. please see below. i would like autohihglight that row where is value in D column.
-
Participate now!
Don’t have an account yet? Register yourself now and be a part of our community!