Help with Range Selection

codye101

New Member
Joined
Jun 9, 2022
Messages
3
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
Platform
  1. Windows
I am currently trying to create a macro that finds a cell with a certain word and selects all cells in a row only if they contain data and replaces that data. This is what I have so far.

If Trim(rngCell) = "Bead Lot" Then
rngCell.Offset(0, 1).Select
Range(rngCell.Offset(0,1), ActiveCell.End(xlToRight)) = "14381"
End If

Currently it works but only if there is more than 1 column of data after the cell containing "Bead Lot" otherwise it fills the entire row with data instead of only replacing existing data.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Welcome to the Board!

Assuming these cells with data are hard-coded (and not formulas), how about this:
VBA Code:
If Trim(rngCell) = "Bead Lot" Then
    Rows(rngCell.Row).SpecialCells(xlCellTypeConstants, 23) = "14381"
End If
 
Upvote 0
Welcome to the Board!

Assuming these cells with data are hard-coded (and not formulas), how about this:
VBA Code:
If Trim(rngCell) = "Bead Lot" Then
    Rows(rngCell.Row).SpecialCells(xlCellTypeConstants, 23) = "14381"
End If
Oh that seems to work pretty well but it's replacing the "Bead Lot" cell with the number also now.
 
Upvote 0
Oh that seems to work pretty well but it's replacing the "Bead Lot" cell with the number also now.
It wasn't quite clear that you wanted to leave that value. You can just set it back, i.e.
VBA Code:
If Trim(rngCell) = "Bead Lot" Then
    Rows(rngCell.Row).SpecialCells(xlCellTypeConstants, 23) = "14381"
    rngCell = "Bead Lot"
End If
 
Upvote 0
Solution
It wasn't quite clear that you wanted to leave that value. You can just set it back, i.e.
VBA Code:
If Trim(rngCell) = "Bead Lot" Then
    Rows(rngCell.Row).SpecialCells(xlCellTypeConstants, 23) = "14381"
    rngCell = "Bead Lot"
End If
Oh that worked, thank you so much!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,249
Members
449,075
Latest member
staticfluids

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