ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   If than copy function / Macro (https://www.excelbanter.com/excel-worksheet-functions/82175-if-than-copy-function-macro.html)

Sweetetc

If than copy function / Macro
 
I have two worksheets.

The two columns that are as follows
Column A Column B
19765L819 2
19765H560 1
19765L538 0
19765N435 3

I want to create a function or macro that will list the numbers
in column A, the number of times indicated in column B
So the result of the above in a new worksheet column A
should look like:

19765L819
19765L819
19765H560
19765N435
19765N435
19765N435

Thanks
Liz
--
Thanks
ETC

Duke Carey

If than copy function / Macro
 
Try this code

There are instructions here for copying the code to your workbook:

http://www.contextures.com/xlvba01.html

David McRitchie has instructions for getting started with macros:

http://www.mvps.org/dmcritchie/excel/getstarted.htm





Sub CopyTextValues()
Dim rng As Range
Dim rngSource As Range
Dim x As Long
Dim y As Integer
Dim ws As Worksheet

Set rngSource = Selection

Set ws = ActiveWorkbook.Worksheets.Add

x = 1
For Each rng In rngSource
y = rng.Offset(0, 1)
If y 0 Then
ws.Cells(x, 1).Resize(y, 1) = rng
End If
x = x + y
Next rng

End Sub


"Sweetetc" wrote:

I have two worksheets.

The two columns that are as follows
Column A Column B
19765L819 2
19765H560 1
19765L538 0
19765N435 3

I want to create a function or macro that will list the numbers
in column A, the number of times indicated in column B
So the result of the above in a new worksheet column A
should look like:

19765L819
19765L819
19765H560
19765N435
19765N435
19765N435

Thanks
Liz
--
Thanks
ETC


Duke Carey

If than copy function / Macro
 
Important Oversight on My Part!!

In order for the code in the previous post to work, you must select the
labels in column A before running the macro


"Sweetetc" wrote:

I have two worksheets.

The two columns that are as follows
Column A Column B
19765L819 2
19765H560 1
19765L538 0
19765N435 3

I want to create a function or macro that will list the numbers
in column A, the number of times indicated in column B
So the result of the above in a new worksheet column A
should look like:

19765L819
19765L819
19765H560
19765N435
19765N435
19765N435

Thanks
Liz
--
Thanks
ETC



All times are GMT +1. The time now is 09:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com