Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to write a statement about if then


I am very new to this.
I have a sheet - sheet 1 which has names in column b, c, d and if the number
one is in column A on sheet one, I want it to pull the names in column b,
c, d on sheet 1 to sheet 2 column b, c, d. If sheet 1 column a has z zero
I want it to skip it and go to the next row with a number 1 in column A. You
see, I only want the data on sheet 2 if I have a one in column 1. I want it
to skip all records until it sees a One again in column a sheet one.

Please help

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default How to write a statement about if then

run this macro:

Private Sub CommandButton1_Click()

Set rngSource = Sheet1.Range("A1:C5")
Set rngDest = Sheet2.Range("A1")

j = 1
For i = 1 To rngSource.Rows.Count
If rngSource(i, 1) = 1 Then
rngDest(j, 2) = rngSource(i, 2)
rngDest(j, 3) = rngSource(i, 3)
rngDest(j, 4) = rngSource(i, 4)
j = j + 1
End If
Next i

End Sub



Mangesh
"Baffle, Atlanta, Ga" wrote in
message ...

I am very new to this.
I have a sheet - sheet 1 which has names in column b, c, d and if the

number
one is in column A on sheet one, I want it to pull the names in column

b,
c, d on sheet 1 to sheet 2 column b, c, d. If sheet 1 column a has z

zero
I want it to skip it and go to the next row with a number 1 in column A.

You
see, I only want the data on sheet 2 if I have a one in column 1. I want

it
to skip all records until it sees a One again in column a sheet one.

Please help



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default How to write a statement about if then

Hi,
This will copy columns B,C and D. Place this code in a general module
in your workbook.

Sub CopySelectedRows()

Dim iLastRow As Long
Dim i As Long
Dim rng As Range, outrng As Range
Dim ws1 As Worksheet, ws2 As Worksheet


Set ws1 = ActiveWorkbook.Worksheets("sheet1")
Set ws2 = ActiveWorkbook.Worksheets("sheet2")

Set outrng = ws2.Range("B2") ' Set outrng to 2nd row in sheet2

ws1.Activate
With Activesheet

iLastRow = Cells(Rows.Count, "A").End(xlUp).Row ' Find last row in
column A

For i = 2 To iLastRow ' Assumes header row
If Cells(i, "A").Value = 1 Then
Set rng = Cells(i, "B").Resize(1, 3) ' set range to columns B to D
rng.Copy outrng ' Copy to sheet2
Set outrng = outrng.Offset(1, 0) ' set outrng to next row
End If
Next i

End With

End Sub



"Baffle, Atlanta, Ga" wrote:


I am very new to this.
I have a sheet - sheet 1 which has names in column b, c, d and if the number
one is in column A on sheet one, I want it to pull the names in column b,
c, d on sheet 1 to sheet 2 column b, c, d. If sheet 1 column a has z zero
I want it to skip it and go to the next row with a number 1 in column A. You
see, I only want the data on sheet 2 if I have a one in column 1. I want it
to skip all records until it sees a One again in column a sheet one.

Please help

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
better way to write a count if statement? luscioussarita Excel Worksheet Functions 3 March 27th 08 08:32 PM
How do I write a basic VLOOKUP statement? Maureen New Users to Excel 7 September 25th 07 03:22 PM
How do I write a compound if statement? Diane Excel Worksheet Functions 5 May 17th 07 08:52 PM
How do you write an if statement that replaces #DIV/0! with 0 caliskier Excel Discussion (Misc queries) 6 March 10th 06 03:22 AM
how do I write the date in an if statement Susan Hayes Excel Worksheet Functions 1 August 23rd 05 09:29 PM


All times are GMT +1. The time now is 04:48 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"