Showing posts with label VBA. Show all posts
Showing posts with label VBA. Show all posts

Tuesday, May 5, 2026

How to copy active cell in excel - VBA - How to copy and fill color of row in excel- VBA -Macro

ActiveCell.Copy

or

 Sub Macro1()

ActiveCell.Copy

ActiveCell.EntireRow.Interior.Color = 5296274

End Sub


or

 Sub Macro1()

ActiveCell.Copy

With ActiveCell.Row.Interior

        .Pattern = xlSolid

        .PatternColorIndex = xlAutomatic

        .Color = 5287936

        .TintAndShade = 0

        .PatternTintAndShade = 0

    End With

End Sub


ref:- https://www.mrexcel.com/board/threads/vba-command-for-copying-active-cell-content-only.978747/

https://www.reddit.com/r/excel/comments/axgoth/vba_code_to_color_a_row_whole_up_until_a_certain/



Friday, April 10, 2026

select random range cell copy in vba excel - copy random cell in excel macro

 Sub Macro3()

    Dim Rng As Range

    Dim randomIdx As Long

   

    ' Set your target range

    Set Rng = Range("K3:K4591")


    ' Initialize the random number generator

    Randomize


    ' Generate a random index between 1 and the total number of cells

    randomIdx = Int(Rnd * Rng.Cells.Count) + 1

    

    ' Select the cell at that index

    Rng.Cells(randomIdx).Select

     Selection.Copy

End Sub


Monday, December 29, 2025

Single left click in VBA - Excel

 


    Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

    Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)



' Define the mouse events

Public Const MOUSEEVENTF_LEFTDOWN = &H2

Public Const MOUSEEVENTF_LEFTUP = &H4

Public Const MOUSEEVENTF_ABSOLUTE = &H8000

Public Const MOUSEEVENTF_MOVE = &H1


Sub SimulateLeftClick(ByVal x As Long, ByVal y As Long)

    ' Move the cursor to the specified coordinates (screen coordinates)

    SetCursorPos x, y

    

    ' Perform the left click (Down and then Up)

    mouse_event MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0

    mouse_event MOUSEEVENTF_LEFTUP, 0, 0, 0, 0

End Sub


Sub TestClick()

    ' Clicks at screen coordinates X=50, Y=50

    Call SimulateLeftClick(40, 200)

End Sub


Wednesday, December 10, 2025

How to copy and paste in notepad excel with Arrow VBA

 Sub CommandButton1_Click()


    Shell "Notepad.exe", vbNormalFocus


    Dim I As Integer


    SendKeys "one"


    SendKeys "{Enter}"

     Application.Wait (Now + TimeValue("00:00:01"))

    SendKeys "^a"

     Application.Wait (Now + TimeValue("00:00:01"))

     SendKeys "^c"

     Application.Wait (Now + TimeValue("00:00:01"))

    SendKeys "{right}"

 Application.Wait (Now + TimeValue("00:00:01"))

    SendKeys "two"

 Application.Wait (Now + TimeValue("00:00:01"))

End Sub


or without interval of time


 Sub CommandButton1_Click()

   Shell "Notepad.exe", vbNormalFocus

Application.Wait (Now + TimeValue("00:00:03"))

    Dim I As Integer

 Dim z As Integer

For z = 1 To 50

    SendKeys "one"

    SendKeys "{Enter}"

    SendKeys "^a"

   SendKeys "^c"

    SendKeys "{right}"

    SendKeys "two"

  Next z

End Sub



How to send up and down keys in Excel or VBA

 https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/sendkeys-statement

Monday, November 24, 2025

How to open Application in Excel VBA - How to open Notepad in Excel VBA - How to open Notepad and send keys in Excel VBA

 Sub CommandButton1_Click()

    Shell "Notepad.exe", vbNormalFocus

    Dim I As Integer

    SendKeys "one"

    SendKeys "{Enter}"

    SendKeys "two"

End Sub


Monday, November 17, 2025

How to stop applicaion in seconds in excel - step by step macro wait for one second - Excel Sleep

 Application.Wait (Now + TimeValue("00:00:01"))

or

Application.Wait Now + TimeSerial(0, 0, 5)


Note: This is only work in Excel VBA, Not in Word VBA.

How to copy a cell in Excel with VBA and how to show MessageBox in excel - alert in Excel

  Selection.Copy

 MsgBox "Copied ---- " & Selection


Note:- Copy Only a single cell , if more than one cell copied, it will give error

Thursday, September 11, 2025