Search for column name in table, replace visible values only in the column

Somewhere

New Member
Joined
Mar 1, 2013
Messages
19
Hi

This is what I am trying to achieve:

1. Enter the column name to find into cell B2
2. Enter the value to populate into this column
IMG_6368.PNG
into cell B3, however the table will be filtered so only visible cells are to be updated.

Column_Name 1 will always have a value present in each row so this can be used to set the range?

Thanks in advance.

Example Image:

https://www.dropbox.com/s/xbl9g7c2c6rjnps/IMG_6368.PNG?dl=0


IMG_6368.PNG
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
How about
Code:
Sub Somewhere()
   With ActiveSheet.ListObjects("[COLOR=#ff0000]Table1[/COLOR]").ListColumns(Range("B2").Value)
      .DataBodyRange.SpecialCells(xlVisible).Value = Range("B3").Value
   End With
End Sub
change table name to suit
 
Upvote 0
Hello,

I can't view files (work firewall)

You don't give the name of the Table but maybe this little code can help.

It searches for a column the same as that in B2 and replaces all visible rows in that column with the data in B3
You should be able to amend this code to suit

Code:
Sub FindAndReplace()
    Dim tbl As ListObject 'variable to store the table
    Dim lc As ListColumn
    Dim FindColumn, ReplaceValue As String
    Dim Found As Boolean
    
    
    FindColumn = Range("B2")
    ReplaceValue = Range("B3")
    
    'assume we are searching the only table on the sheet. If not change accordingly
    Set tbl = Me.ListObjects(1)
    
    For Each lc In tbl.ListColumns
        If lc.Name = FindColumn Then
            lc.DataBodyRange.SpecialCells(xlCellTypeVisible) = ReplaceValue
            Found = True
            Exit Sub
        End If
    Next lc
    If Not Found Then MsgBox ("Column Not Found")
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,704
Messages
6,173,984
Members
452,540
Latest member
haasro02

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