Autofilter/Autopopulate

ianfrancis56

New Member
Joined
Aug 10, 2011
Messages
34
All,

I am new to the forum and relative new to VBA for excel. I am trying to populate a table based off of another table. The source table has labor categories in column G and, potentially, a cost figure in column Q. I want to check to see if there is a cost figure for each labor category and, if so, populate the second table with the labor category, but skip over it if there is no cost figure. I am probably way off, but it seems with this code I either get all or nothing. Thanks for any help!


Sub PEOFTECalc_Click()

Dim i%, LabCatCount%

LabCatCount = IsEmpty(Sheets("Labor").Range("Q" & i + 4))


For i = 1 To 31
If LabCatCount = True Then
Range("G" & i + 12) = Sheets("Labor").Range("G" & i + 4)
End If
Next i

End Sub
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Hi,

Welcome to the forum!

One question: both tables in the sheet Labor or in different sheets?

M.
 
Upvote 0
Thanks! The Labor Category and Cost are in Sheets("Labor") and the the table is in a separate worksheet. As well, there is a formula in all of the cost category cells
 
Upvote 0
I'm not seeing your data (you havent post a sample...) so i'm following your original macro and in some way trying to guess ;) , so please try the macro below in a test-workbook

Code:
Sub PEOFTECalc_Click()
    Dim i As Long
 
    With ActiveSheet
        For i = 1 To 31
            If .Range("Q" & i + 4) <> "" Then
                .Range("G" & i + 12) = Sheets("Labor").Range("G" & i + 4)
            End If
        Next i
    End With
End Sub

HTH

M.
 
Upvote 0
Wow that almost has it! Amazing! I knew With had something to do with it, you'll have to forgive me, I have only been working with VBA for ~3 weeks now.

One more problem: How do I get rid of the space between the values? For example, the first result comes in and the next one is 10 rows farther down. I want it to show up right under the first result rather than 10 rows down. Any suggestions? Thanks again!

Pasted below is the code you gave me (one slight modification to make it work).

Sub PEOFTECalc_Click()

Dim i As Integer

With ActiveSheet
For i = 1 To 31
If Sheets("Labor").Range("Q" & i + 4) <> "" Then
.Range("G" & i + 12) = Sheets("Labor").Range("G" & i + 4)
End If
Next i
End With
End Sub
 
Upvote 0
If i understood correctly, try this

Code:
Sub PEOFTECalc_Click()
    Dim i As Long, lin As Long
 
    lin = 13
    With ActiveSheet
        For i = 1 To 31
            If .Range("Q" & i + 4) <> "" Then
                .Range("G" & lin) = Sheets("Labor").Range("G" & i + 4)
                lin = lin + 1
            End If
        Next i
    End With
End Sub

One advice: when posting code use the button #
It generates two tags
Code:
 and ['/CODE] without the ' and paste the code inside the tags
 
And always use indentation
 
M.
 
Upvote 0
That was PERFECT! Thank you so much for helping a rookie, I will make fast work of catching up. Is there a text you recommend?
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,768
Members
452,940
Latest member
rootytrip

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