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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,223,888
Messages
6,175,212
Members
452,618
Latest member
Tam84

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