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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
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,224,820
Messages
6,181,159
Members
453,021
Latest member
Justyna P

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