activecell offset help

aspence

Board Regular
Joined
Feb 10, 2009
Messages
130
I have the code below, which defines a range in column K then searches that range for any cell where the value equals "Customer Tickets". From there, I am having trouble getting what I want out of the macro.

What I need is:
For every occurance of "Customer Tickets" in column K, i need some of the data in the corresponding rows to be changed to "Checked".

For example, if the macro finds cell K19 to be equal to "Customer Tickets, then I need the value in cells M19:O19 to all equal "Checked" and I cant seem to get the offset to work correctly.

Code:
Sub CustTick()
 
Dim metric As Range
' highlights variable range in column K
LastRow = Range("K1").End(xlDown).Row
Range(Cells(2, "K"), Cells(LastRow, "K")).Select
' sets selection as the range to search
Set metric = Selection
For Each Cell In metric
  If Cell = "Customer Tickets" Then
    ' need macro
  End If
Next Cell
End Sub

Any ideas?
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
First off, it's very rare that you need to Select anything in VBA. You can work with ranges directly.


Code:
Sub test()
Dim c As Long, d As Range
c = Range("K" & Rows.Count).End(xlUp).Row
For Each d In Range("K1:K" & c)
    If UCase(d) = "CUSTOMER TICKETS" Then d.Offset(, 2).Resize(, 3) = "Checked"
Next
End Sub
 
Upvote 0
Code:
d.Offset(, 2).Resize(, 3)
Is this a range selection?

If I needed this to do something other than change the cell value, like format the color to red instead of changing the cell value, will it do this with each cell in the range?
 
Upvote 0
It's specifying a range, but it's not actually Selecting it.

Sure specify what you want.
Code:
d.Offset(, 2).Resize(, 3).Interior.Color=vbRed
 
Upvote 0
As you stated earlier
it's very rare that you need to Select anything in VBA. You can work with ranges directly.

Is it possible to take this new specified range and compare each cell in the range to another variable or cell? For example, if each of the cell in the range have values greater than the cell value of column L in the same row, then either change the cell value or format the color.

I really hope I am not overcomlicating things. Thanks for the help so far.
 
Upvote 0
The form I am trying to modify currently uses conditional formatting. The problem is, there is so much repetative information in the workbook with a large amount of formatting, that when you attempt to filter data, the workbook freezes for extended periods of time and I am looking for alternatives to avoid that situation. When I clear the formatting from the workbook and modify the cells directly, the data filtering process runs very smoothly.
 
Upvote 0
If I understand your issue, you want to go through several rows, and for each row if the value in Col K = "something" then change the values in Col M, N, O to something. Here's my recommendation:

lastRow = Range("A1000000").End(xlUp).Row 'I prefer xlUp instead of xlDown in case you have any blanks in that column, or just pick the column you know can't have blanks
startRow = 2

For r = startRow To lastRow
If Cells(r, "K").Value = "Customer Ticket" Then
Cells(r,"M").Value = whatevervalueyouwant
Cells(r, "N").Value = whatevervalueyouwant
Cells(r, "O").Value = whatevervalueyouwant
End If
Next r
 
Upvote 0
Do you want to individually change each cell that has a greater value than Column L, or only if they all do,and change them as a whole?
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

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