• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA code to customer use of button

I have data in sheet 2 dealer wise and product wise. I have created two button Dealer and product in sheet 1.

I want VBA code so that if i click on Dealer button. VBA code should copy dealer wise information in sheet 2 and paste into Sheet 1 right from cell A1. and if i click on Product button VBA should copy product wise information in sheet 2 and paste it into cell A1. Please find attached the sample data.
 

Attachments

  • Option buttion sample data.xlsx
    13.1 KB · Views: 4
Attach these codes to your buttons

Code:
Sub Dealer()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    s1.Range("A1:B" & Rows.Count).End(xlUp).Row.ClearContents
    Dim lr As Long
    lr = s2.Range("A" & Rows.Count).End(xlUp).Row
    s2.Range("A4:B" & lr).Copy s1.Range("A1")
End Sub

Code:
Sub Product()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    s1.Range("A1:B" & Rows.Count).End(xlUp).Row.ClearContents
    Dim lr As Long
    lr = s2.Range("E" & Rows.Count).End(xlUp).Row
    s2.Range("E4:F" & lr).Copy s1.Range("A1")
End Sub
 
hii @Kumar Shanmugam ,

Go to developer tab ,insert module copy code and paste and run it.


Code:
Sub Dealer_data()
'
' Macro4 Macro
'

'
    Sheets("Sheet2").Select
    Columns("A:B").Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Application.CutCopyMode = False
End Sub
Code:
Sub Product_data()
'
' Product_data Macro
'
' Keyboard Shortcut: Ctrl+Shift+P
'
    Sheets("Sheet2").Select
    Columns("E:F").Select
    Selection.Copy
    Sheets("Sheet1").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Range("A1").Select
    Application.CutCopyMode = False
End Sub


Regard
Rahul shewale
 

Attachments

  • Option buttion sample data.xlsm
    19.3 KB · Views: 1
Back
Top