View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ariel Dugan[_2_] Ariel Dugan[_2_] is offline
external usenet poster
 
Posts: 5
Default Macro with Variable Data

Sorry,

I am a novice myself. Here is code that works properly, I hope. Notice I
got rid of that J variable, and instead am just checking in "A4" is blank to
decide where to start the pasting, and had to activate the "Ebony G" sheet in
the "Else" section of the "If" structure.

Seems to work now. Let me know.

Sub GetData()
Dim n As Integer, i As Integer
Dim rng As Range



Sheets("Daily Attendance").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
Sheets("Daily Attendance").Activate
If Cells(i, "A").Value = "Glover, Ebony" Then
Range("A" & i & ":L" & i).Copy
Sheets("Ebony G").Activate
If Range("A4") = "" Then
Set rng = Worksheets("Ebony G").Range("A4")
rng.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False

Else
Sheets("Ebony G").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row + 1
Set rng = Worksheets("Ebony G").Range("A" & n)
rng.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End If
End If
Next i

End Sub

"jeannie v" wrote:

Good Morning, Ariel:

We are getting so close I can taste it.....It works so far for Ebony except
that the first line of data extracted is pasted where it's supposed to be,
but the other lines paste at the bottom of my spreadsheet with blank lines in
between....I want the data lines that are extracted to appear on "Ebony G"
worksheet right underneath each other with no blank lines. How can we do
that?
--
jeannie v


"Ariel Dugan" wrote:

Hi Jeannie,

This worked for me.

Sub GetData()
Dim n As Integer, i As Integer, j As Integer
Dim rng As Range

j = 0

Sheets("Daily Attendance").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
Sheets("Daily Attendance").Activate
If Cells(i, "A").Value = "Glover, Ebony" Then
Range("A" & i & ":L" & i).Copy
Sheets("Ebony G").Activate
If j = 0 Then
Set rng = Worksheets("Ebony G").Range("A4")
rng.Select
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
j = j + 1
Else
n = Cells(Rows.Count, "A").End(xlUp).Row + 1
Set rng = Worksheets("Ebony G").Range("A" & n)
rng.Select
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
End If
Next i



End Sub



"jeannie v" wrote:

Hi Ariel: Me again...What can I add to the macro to Paste Special Values
when it pops in worksheet 1?
--
jeannie v


"Ariel Dugan" wrote:

Did you want the next four lines down?

If so, then replace this line

Range("A" & i & ":L" & i).copy

with this line

Range("A" & i & ":L" & i +4).copy

and that should work.

HTH
Ariel

"jeannie v" wrote:

Hi: I apologize that I am a real novice in Macros.

This is the macro that works great, but I want to tweak it just a little.

Sheets("Daily Attendance").Activate
n = Cells(Rows.Count, "A").End(xlUp).Row
For i = 1 To n
If Cells(i, "A").Value = "Glover, Ebony" Then
v = Cells(i, "C").Value
Exit For
End If
Next
Sheets("Ebony G").Activate
Range("N21").Value = v


I want to create a macro to do almost the same thing, except I want it to
retrieve more than 1 field of data for the person...Can I tweak this one to
do what I want?

I want it to say say: If "Glover, Ebony" is found by auto-filter in Column A
from Cell A2:A160 in Agent Login-Logout, Take the data in Column A through
Column L and copy to Worksheet 1 "Ebony G" in Cells A4 to L14.

Any help would be appreciated.
--
jeannie v