Using VBA select cell with word

ajith

Board Regular
Joined
Nov 21, 2012
Messages
215
Office Version
  1. 2016
Platform
  1. Windows
How to select using VBA the cell with the result as "Total" in the range C4 to C100.
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
Try this:
Code:
Sub My_Find()
'Modified 7/8/18 5:45 AM EDT
Dim SearchString As String
Dim SearchRange As Range
SearchString = "Total"
Set SearchRange = Range("C4:C100").Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
    If SearchRange Is Nothing Then MsgBox "The Value" & SearchString & vbNewLine & "Not found": Exit Sub
SearchRange.Select
End Sub
 
Last edited:
Upvote 0
Sir,
In continuation to my query. If I want to paste the following code starting from that cell which contains "Total", how should I proceed. Thanks in advance.

Code:
Sub CopyState2()'
' CopyState2 Macro
'


'
    Sheets("Arr Statement").Select
    Range("C5:L89").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Draft").Select
    Range("C89").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.ClearContents
    Sheets("Arr Statement").Select
    Selection.Copy
    Sheets("Draft").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
End Sub


Thank you.
 
Upvote 0
Sir,
I could do that as follows,

Code:
Sub CopyState3()
'
' CopyState2 Macro
'


'
    Sheets("Arr Statement").Select
    Range("C5:L89").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Draft").Select
    Dim SearchString As String
Dim SearchRange As Range
SearchString = "Total"
Set SearchRange = Range("C4:C1046").Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
    If SearchRange Is Nothing Then MsgBox "The Value" & SearchString & vbNewLine & "Not found": Exit Sub
SearchRange.Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.ClearContents
    Sheets("Arr Statement").Select
    Selection.Copy
    Sheets("Draft").Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
End Sub

I had to do PasteSpecial twice as even after selecting "Value and number formatting" under paste special the formulas are seen. I am using MS office Professional Plus 2016.

Thank you,
 
Last edited:
Upvote 0
Maybe something like this...

Code:
Sub CopyState3()
Dim SearchString As String
Dim SearchRange As Range
SearchString = "Total"
Set SearchRange = Sheets("Draft").Range("C4:C1046").Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
    If SearchRange Is Nothing Then MsgBox "The Value" & SearchString & vbNewLine & "Not found": Exit Sub
SearchRange.Resize(84, 8).Value = Sheets("Arr Statement").Range("C5:L89").Value
End Sub
 
Upvote 0
It would have been great from the start if you had explained in full what your attempting to do.

Like why are you searching for the word Total
Is this the value in the last cell in a particular column with data?
If so there are other ways we would do this.
 
Upvote 0
Sorry sir. I understand that. But If I post many things it will be confusing for the reader. Moreover I don't know to upload an excel sheet along with my query. Earlier someone informed me that it is given in this forum but it is not self explanatory.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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