+ Reply to Thread
Results 1 to 28 of 28

VBA referring to a different sheet, automatically fill cell based on content of other cell

Hybrid View

  1. #1
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    No sir, it will be brought over from the For Sales tab when you hit the Copy Data button on the itmof tab.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    Place this code in the worksheet module for Sheet("itbof")... not in Sheet("itmof"). When you click the 'Copy Data' button and then select Sheet("itbof"), your columns should automatically update.

    Private Sub Worksheet_Activate()
        Dim bottomA As Integer
        bottomA = Range("A" & Rows.Count).End(xlUp).Row
        Dim bottomL As Integer
        bottomL = Range("L" & Rows.Count).End(xlUp).Row
        Dim rng1 As Range
        Dim rng2 As Range
        For Each rng1 In Sheets("itbof").Range("A2:A" & bottomA)
            If rng1 <> "" Then
                Cells(rng1.Row, 3).Value = "A"
                Cells(rng1.Row, 20).Value = "N"
            End If
        Next rng1
        
        For Each rng2 In Sheets("itbof").Range("L2:L" & bottomL)
            If rng2 <> "" Then
                Cells(rng2.Row, 9).Value = Cells(rng2.Row, 12).Value * 1.08
            End If
        Next rng2
    End Sub

  3. #3
    Registered User
    Join Date
    02-04-2013
    Location
    Buffalo, New York
    MS-Off Ver
    Excel 2010
    Posts
    27

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    OK, I'll rephrase this, I did some more testing, and the only time it errors out is if I switch over to the itbof tab before I hit the copy data button, other than that it works great. To make it "dummy proof" is there any way to just make it run after I hit the itbof tab? This way it doesn't matter if we accidentally switch to that tab first before the copy data button is pressed...

    Thanks, I appreciate everything you've done so far!

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: VBA referring to a different sheet, automatically fill cell based on content of other

    I would like to make a suggestion. First, remove the code from the worksheet module and put it into a regular module and change the name of the macro so that it's not a Worksheet_Activate event. Then you can run the macro by assigning it to a button on either worksheet or you can call the macro from your "Copy Data" macro. If you call it from the "Copy Data" macro, it will complete the "itbof" sheet automatically when it completes the "itmof" sheet. If you want to keep the two tasks separate, then assign it to a button. I hope that helps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1