apply formula to SpecialCells(xlCellTypeVisible)

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,057
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
This code is working all perfect it finds the column name, but the problem is I am not able to apply formula to the visible cells any suggestion


VBA Code:
Sub fillrejectionflag()

    Dim co12 As String, c10find As Range
    Dim co13 As String, cc12find As Range

    co12 = "Cand. Final Status"
    co13 = "Email Flag"
    Lastrow = Cells(Rows.Count, 1).End(xlUp).Row + 1
With Worksheets("Candidate Master") '<-- reference your relevant worksheet (change "AF" to your actual worksheet name)
        With .Range("A1", .Cells(1, .Columns.Count).End(xlToLeft)) '<-- reference its row 1 cells from column 1 rightwards to last not empty one
            
            Set c10find = .Rows(1).Find(what:=co12, LookIn:=xlValues, lookat:=xlWhole)
            Set cc12find = .Rows(1).Find(what:=co13, LookIn:=xlValues, lookat:=xlWhole)
            If Not c10find Is Nothing Then '<-- if the header has been found
            [B]Range(c10find & Lastrow).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "1"  '' Problem is here
            Range(cc12find & Lastrow).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=now()" ''Problem is here[/B]
                ' do your things
            End If
        End With
        '.AutoFilterMode = False '<-- show all rows back and remove autofilter buttons
    End With
End sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I am not able to apply formula to the visible cells


VBA Code:
            Range(cc12find & Lastrow).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=now()" ''Problem is here[/B]

What happens when you run this code that is different than what you want to happen?
 
Upvote 0
Try this:-
VBA Code:
Sub fillrejectionflag()

    Dim co12 As String, c10find As Range
    Dim co13 As String, cc12find As Range
   
    Dim Lastrow As Long
    Dim CandColNo As Long, EmailColNo As Long
   
    co12 = "Cand. Final Status"
    co13 = "Email Flag"
    Lastrow = Cells(Rows.Count, 1).End(xlUp).Row 
    With Worksheets("Candidate Master") '<-- reference your relevant worksheet (change "AF" to your actual worksheet name)
        With .Range("A1", .Cells(1, .Columns.Count).End(xlToLeft)) '<-- reference its row 1 cells from column 1 rightwards to last not empty one
            Set c10find = .Rows(1).Find(what:=co12, LookIn:=xlValues, lookat:=xlWhole)
            CandColNo = c10find.Column
            Set cc12find = .Rows(1).Find(what:=co13, LookIn:=xlValues, lookat:=xlWhole)
            EmailColNo = cc12find.Column
        End With
           
        If Not c10find Is Nothing Then '<-- if the header has been found
            .Range(.Cells(2, CandColNo), .Cells(Lastrow, CandColNo)).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "1" '' Problem is here
            .Range(.Cells(2, EmailColNo), .Cells(Lastrow, EmailColNo)).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=now()" ''Problem is here
                ' do your things
        End If

        '.AutoFilterMode = False '<-- show all rows back and remove autofilter buttons
    End With
End Sub
 
Upvote 0
Dim co12 As String, c10find As Range Dim co13 As String, cc12find As Range Dim Lastrow As Long Dim CandColNo As Long, EmailColNo As Long co12 = "Cand. Final Status" co13 = "Email Flag" Lastrow = Cells(Rows.Count, 1).End(xlUp).Row With Worksheets("Candidate Master") '<-- reference your relevant worksheet (change "AF" to your actual worksheet name) With .Range("A1", .Cells(1, .Columns.Count).End(xlToLeft)) '<-- reference its row 1 cells from column 1 rightwards to last not empty one Set c10find = .Rows(1).Find(what:=co12, LookIn:=xlValues, lookat:=xlWhole) CandColNo = c10find.Column Set cc12find = .Rows(1).Find(what:=co13, LookIn:=xlValues, lookat:=xlWhole) EmailColNo = cc12find.Column End With If Not c10find Is Nothing Then '<-- if the header has been found .Range(.Cells(2, CandColNo), .Cells(Lastrow, CandColNo)).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "1" '' Problem is here .Range(.Cells(2, EmailColNo), .Cells(Lastrow, EmailColNo)).SpecialCells(xlCellTypeVisible).FormulaR1C1 = "=now()" ''Problem is here ' do your things End If '.AutoFilterMode = False '<-- show all rows back and remove autofilter buttons End With
perfect, its working great.
only think who will =Now() be converted to values ,

sorry missed this part in my first post.
 
Upvote 0
only think who will =Now() be converted to values ,

sorry missed this part in my first post.

Just use Now rather than "=Now()" then you don't need to convert to values
VBA Code:
Range(.Cells(2, EmailColNo), .Cells(Lastrow, EmailColNo)).SpecialCells(xlCellTypeVisible).Value = Now
 
Upvote 0

Forum statistics

Threads
1,214,813
Messages
6,121,706
Members
449,049
Latest member
THMarana

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