Run macro on 2 or 3 pages

Multi tool use
Multi tool use











up vote
0
down vote

favorite












I was given a macro to use, it works fine with 1 pg worksheets but some of my worksheets have 2 or 3 pages. Any idea how I can change the code to do more than 1 page? Any feedback is appreciated. Here is the macro code:



Dim wksAufruf As Worksheet

Dim wkbAufruf As Workbook

Dim wksActive As Worksheet

Dim varDatei As Variant

Option Explicit

Sub DateiAufrufen()
Dim s As String

Set wksActive = ThisWorkbook.Sheets(1)
s = wksActive.Cells(3, 2).Value
'ChDrive ' drive specification
ChDir s ' path specification for the selection dialog"
varDatei = Application.GetOpenFilename("Excel-Dateien (*.xls*), *.xl*")
Set wkbAufruf = Workbooks.Open(varDatei, False, True)
Set wksAufruf = wkbAufruf.Sheets(1)
End Sub
Sub DateiErstellen()

'###admin read out

Dim out As String 'output folder path
Dim head As String 'row of column-headlines
Dim filetype As String 'output filetype

out = wksActive.Cells(5, 2).Value 'output folder path
head = wksActive.Cells(7, 2).Value
If Right(out, 1) <> "" Then
out = out & ""
End If

filetype = wksActive.Cells(9, 2).Value
filetype = Replace(filetype, ".", "")

'###create new file

Dim FSyObjekt As Object 'to create new file

Application.ScreenUpdating = False
Set FSyObjekt = CreateObject("Scripting.FileSystemObject")
Workbooks.Add
Set wksActive = ActiveWorkbook.Sheets(1)

'###pre-work copy data

Dim name As String
Dim r As Integer
Dim c As Integer
Dim r1 As Integer 'row wksActive
Dim i1 As Integer 'row wksAufruf
Dim i2 As Integer 'column wksAufruf
Dim rel As Integer 'first column released


r = wksAufruf.UsedRange.Rows.Count 'last row wksAufruf
c = wksAufruf.UsedRange.Columns.Count 'last column wksAufruf
name = wkbAufruf.name 'file name
r1 = 1

For i2 = 1 To c
If wksAufruf.Cells(head - 1, i2) Like "*RELEASED*" Then
rel = i2
Exit For
End If
Next i2


'###Copy Data
Dim s As String

For i1 = 1 To r
For i2 = 1 To c
If i1 = head Then
s = wksAufruf.Cells(i1, i2) & " " & wksAufruf.Cells(i1 + 1, i2) 'because column headlines in Hawker's lists stretch over two rows
If i2 = c Then
i1 = i1 + 1
End If
Else
s = wksAufruf.Cells(i1, i2).Value
End If
wksActive.Cells(r1, i2) = s
Next i2
r1 = r1 + 1
Next i1

wkbAufruf.Close False 'close without saving

ActiveWorkbook.Sheets(2).Delete 'close cheets 2 and 3 of the newly created worksheet
ActiveWorkbook.Sheets(2).Delete

'delete upper row
For i1 = 1 To head - 1
Rows("1").EntireRow.Delete
Next i1

'delete bottom row
r = wksActive.UsedRange.Rows.Count
For r1 = 1 To r
If wksActive.Cells(r1, 3).Value = "" Then
Exit For 'find row to delete
End If
Next r1

i1 = r1
For r1 = i1 To r
wksActive.Rows(i1).EntireRow.Delete
Next r1


For i2 = 1 To c 'delete empty columns
If wksActive.Cells(1, i2).Value = "" Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " _
Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Then
wksActive.Columns(i2).EntireColumn.Delete
If i2 <= rel Then
rel = rel - 1
End If

If i2 = c Then
Exit For
End If

i2 = i2 - 1
c = c - 1
End If
Next i2

'released and received
For i2 = 1 To wksActive.UsedRange.Columns.Count
s = ""
If i2 > 1 And i2 < rel Then
s = "RECEIVED " & wksActive.Cells(1, i2)
ElseIf i2 >= rel And i2 < wksActive.UsedRange.Columns.Count Then
s = "RELEASED " & wksActive.Cells(1, i2)
Else
s = wksActive.Cells(1, i2)
End If
wksActive.Cells(1, i2) = s
Next i2

Modul2.ColumnManagement wksActive

Dim k As Integer
k = InStr(1, name, ".")
name = Left(name, k - 1)

ActiveWorkbook.SaveAs out & "FD_" & name & "." & filetype
ActiveWorkbook.Close

End Sub

Sub main()
DateiAufrufen
DateiErstellen
End Sub









share|improve this question









New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Where there is sheet(1) change that to 2 or 3 to do the respective sheets.
    – Luuklag
    yesterday










  • avoid too long lines. No one likes horizontal scrolling
    – phuclv
    yesterday















up vote
0
down vote

favorite












I was given a macro to use, it works fine with 1 pg worksheets but some of my worksheets have 2 or 3 pages. Any idea how I can change the code to do more than 1 page? Any feedback is appreciated. Here is the macro code:



Dim wksAufruf As Worksheet

Dim wkbAufruf As Workbook

Dim wksActive As Worksheet

Dim varDatei As Variant

Option Explicit

Sub DateiAufrufen()
Dim s As String

Set wksActive = ThisWorkbook.Sheets(1)
s = wksActive.Cells(3, 2).Value
'ChDrive ' drive specification
ChDir s ' path specification for the selection dialog"
varDatei = Application.GetOpenFilename("Excel-Dateien (*.xls*), *.xl*")
Set wkbAufruf = Workbooks.Open(varDatei, False, True)
Set wksAufruf = wkbAufruf.Sheets(1)
End Sub
Sub DateiErstellen()

'###admin read out

Dim out As String 'output folder path
Dim head As String 'row of column-headlines
Dim filetype As String 'output filetype

out = wksActive.Cells(5, 2).Value 'output folder path
head = wksActive.Cells(7, 2).Value
If Right(out, 1) <> "" Then
out = out & ""
End If

filetype = wksActive.Cells(9, 2).Value
filetype = Replace(filetype, ".", "")

'###create new file

Dim FSyObjekt As Object 'to create new file

Application.ScreenUpdating = False
Set FSyObjekt = CreateObject("Scripting.FileSystemObject")
Workbooks.Add
Set wksActive = ActiveWorkbook.Sheets(1)

'###pre-work copy data

Dim name As String
Dim r As Integer
Dim c As Integer
Dim r1 As Integer 'row wksActive
Dim i1 As Integer 'row wksAufruf
Dim i2 As Integer 'column wksAufruf
Dim rel As Integer 'first column released


r = wksAufruf.UsedRange.Rows.Count 'last row wksAufruf
c = wksAufruf.UsedRange.Columns.Count 'last column wksAufruf
name = wkbAufruf.name 'file name
r1 = 1

For i2 = 1 To c
If wksAufruf.Cells(head - 1, i2) Like "*RELEASED*" Then
rel = i2
Exit For
End If
Next i2


'###Copy Data
Dim s As String

For i1 = 1 To r
For i2 = 1 To c
If i1 = head Then
s = wksAufruf.Cells(i1, i2) & " " & wksAufruf.Cells(i1 + 1, i2) 'because column headlines in Hawker's lists stretch over two rows
If i2 = c Then
i1 = i1 + 1
End If
Else
s = wksAufruf.Cells(i1, i2).Value
End If
wksActive.Cells(r1, i2) = s
Next i2
r1 = r1 + 1
Next i1

wkbAufruf.Close False 'close without saving

ActiveWorkbook.Sheets(2).Delete 'close cheets 2 and 3 of the newly created worksheet
ActiveWorkbook.Sheets(2).Delete

'delete upper row
For i1 = 1 To head - 1
Rows("1").EntireRow.Delete
Next i1

'delete bottom row
r = wksActive.UsedRange.Rows.Count
For r1 = 1 To r
If wksActive.Cells(r1, 3).Value = "" Then
Exit For 'find row to delete
End If
Next r1

i1 = r1
For r1 = i1 To r
wksActive.Rows(i1).EntireRow.Delete
Next r1


For i2 = 1 To c 'delete empty columns
If wksActive.Cells(1, i2).Value = "" Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " _
Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Then
wksActive.Columns(i2).EntireColumn.Delete
If i2 <= rel Then
rel = rel - 1
End If

If i2 = c Then
Exit For
End If

i2 = i2 - 1
c = c - 1
End If
Next i2

'released and received
For i2 = 1 To wksActive.UsedRange.Columns.Count
s = ""
If i2 > 1 And i2 < rel Then
s = "RECEIVED " & wksActive.Cells(1, i2)
ElseIf i2 >= rel And i2 < wksActive.UsedRange.Columns.Count Then
s = "RELEASED " & wksActive.Cells(1, i2)
Else
s = wksActive.Cells(1, i2)
End If
wksActive.Cells(1, i2) = s
Next i2

Modul2.ColumnManagement wksActive

Dim k As Integer
k = InStr(1, name, ".")
name = Left(name, k - 1)

ActiveWorkbook.SaveAs out & "FD_" & name & "." & filetype
ActiveWorkbook.Close

End Sub

Sub main()
DateiAufrufen
DateiErstellen
End Sub









share|improve this question









New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Where there is sheet(1) change that to 2 or 3 to do the respective sheets.
    – Luuklag
    yesterday










  • avoid too long lines. No one likes horizontal scrolling
    – phuclv
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I was given a macro to use, it works fine with 1 pg worksheets but some of my worksheets have 2 or 3 pages. Any idea how I can change the code to do more than 1 page? Any feedback is appreciated. Here is the macro code:



Dim wksAufruf As Worksheet

Dim wkbAufruf As Workbook

Dim wksActive As Worksheet

Dim varDatei As Variant

Option Explicit

Sub DateiAufrufen()
Dim s As String

Set wksActive = ThisWorkbook.Sheets(1)
s = wksActive.Cells(3, 2).Value
'ChDrive ' drive specification
ChDir s ' path specification for the selection dialog"
varDatei = Application.GetOpenFilename("Excel-Dateien (*.xls*), *.xl*")
Set wkbAufruf = Workbooks.Open(varDatei, False, True)
Set wksAufruf = wkbAufruf.Sheets(1)
End Sub
Sub DateiErstellen()

'###admin read out

Dim out As String 'output folder path
Dim head As String 'row of column-headlines
Dim filetype As String 'output filetype

out = wksActive.Cells(5, 2).Value 'output folder path
head = wksActive.Cells(7, 2).Value
If Right(out, 1) <> "" Then
out = out & ""
End If

filetype = wksActive.Cells(9, 2).Value
filetype = Replace(filetype, ".", "")

'###create new file

Dim FSyObjekt As Object 'to create new file

Application.ScreenUpdating = False
Set FSyObjekt = CreateObject("Scripting.FileSystemObject")
Workbooks.Add
Set wksActive = ActiveWorkbook.Sheets(1)

'###pre-work copy data

Dim name As String
Dim r As Integer
Dim c As Integer
Dim r1 As Integer 'row wksActive
Dim i1 As Integer 'row wksAufruf
Dim i2 As Integer 'column wksAufruf
Dim rel As Integer 'first column released


r = wksAufruf.UsedRange.Rows.Count 'last row wksAufruf
c = wksAufruf.UsedRange.Columns.Count 'last column wksAufruf
name = wkbAufruf.name 'file name
r1 = 1

For i2 = 1 To c
If wksAufruf.Cells(head - 1, i2) Like "*RELEASED*" Then
rel = i2
Exit For
End If
Next i2


'###Copy Data
Dim s As String

For i1 = 1 To r
For i2 = 1 To c
If i1 = head Then
s = wksAufruf.Cells(i1, i2) & " " & wksAufruf.Cells(i1 + 1, i2) 'because column headlines in Hawker's lists stretch over two rows
If i2 = c Then
i1 = i1 + 1
End If
Else
s = wksAufruf.Cells(i1, i2).Value
End If
wksActive.Cells(r1, i2) = s
Next i2
r1 = r1 + 1
Next i1

wkbAufruf.Close False 'close without saving

ActiveWorkbook.Sheets(2).Delete 'close cheets 2 and 3 of the newly created worksheet
ActiveWorkbook.Sheets(2).Delete

'delete upper row
For i1 = 1 To head - 1
Rows("1").EntireRow.Delete
Next i1

'delete bottom row
r = wksActive.UsedRange.Rows.Count
For r1 = 1 To r
If wksActive.Cells(r1, 3).Value = "" Then
Exit For 'find row to delete
End If
Next r1

i1 = r1
For r1 = i1 To r
wksActive.Rows(i1).EntireRow.Delete
Next r1


For i2 = 1 To c 'delete empty columns
If wksActive.Cells(1, i2).Value = "" Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " _
Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Then
wksActive.Columns(i2).EntireColumn.Delete
If i2 <= rel Then
rel = rel - 1
End If

If i2 = c Then
Exit For
End If

i2 = i2 - 1
c = c - 1
End If
Next i2

'released and received
For i2 = 1 To wksActive.UsedRange.Columns.Count
s = ""
If i2 > 1 And i2 < rel Then
s = "RECEIVED " & wksActive.Cells(1, i2)
ElseIf i2 >= rel And i2 < wksActive.UsedRange.Columns.Count Then
s = "RELEASED " & wksActive.Cells(1, i2)
Else
s = wksActive.Cells(1, i2)
End If
wksActive.Cells(1, i2) = s
Next i2

Modul2.ColumnManagement wksActive

Dim k As Integer
k = InStr(1, name, ".")
name = Left(name, k - 1)

ActiveWorkbook.SaveAs out & "FD_" & name & "." & filetype
ActiveWorkbook.Close

End Sub

Sub main()
DateiAufrufen
DateiErstellen
End Sub









share|improve this question









New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I was given a macro to use, it works fine with 1 pg worksheets but some of my worksheets have 2 or 3 pages. Any idea how I can change the code to do more than 1 page? Any feedback is appreciated. Here is the macro code:



Dim wksAufruf As Worksheet

Dim wkbAufruf As Workbook

Dim wksActive As Worksheet

Dim varDatei As Variant

Option Explicit

Sub DateiAufrufen()
Dim s As String

Set wksActive = ThisWorkbook.Sheets(1)
s = wksActive.Cells(3, 2).Value
'ChDrive ' drive specification
ChDir s ' path specification for the selection dialog"
varDatei = Application.GetOpenFilename("Excel-Dateien (*.xls*), *.xl*")
Set wkbAufruf = Workbooks.Open(varDatei, False, True)
Set wksAufruf = wkbAufruf.Sheets(1)
End Sub
Sub DateiErstellen()

'###admin read out

Dim out As String 'output folder path
Dim head As String 'row of column-headlines
Dim filetype As String 'output filetype

out = wksActive.Cells(5, 2).Value 'output folder path
head = wksActive.Cells(7, 2).Value
If Right(out, 1) <> "" Then
out = out & ""
End If

filetype = wksActive.Cells(9, 2).Value
filetype = Replace(filetype, ".", "")

'###create new file

Dim FSyObjekt As Object 'to create new file

Application.ScreenUpdating = False
Set FSyObjekt = CreateObject("Scripting.FileSystemObject")
Workbooks.Add
Set wksActive = ActiveWorkbook.Sheets(1)

'###pre-work copy data

Dim name As String
Dim r As Integer
Dim c As Integer
Dim r1 As Integer 'row wksActive
Dim i1 As Integer 'row wksAufruf
Dim i2 As Integer 'column wksAufruf
Dim rel As Integer 'first column released


r = wksAufruf.UsedRange.Rows.Count 'last row wksAufruf
c = wksAufruf.UsedRange.Columns.Count 'last column wksAufruf
name = wkbAufruf.name 'file name
r1 = 1

For i2 = 1 To c
If wksAufruf.Cells(head - 1, i2) Like "*RELEASED*" Then
rel = i2
Exit For
End If
Next i2


'###Copy Data
Dim s As String

For i1 = 1 To r
For i2 = 1 To c
If i1 = head Then
s = wksAufruf.Cells(i1, i2) & " " & wksAufruf.Cells(i1 + 1, i2) 'because column headlines in Hawker's lists stretch over two rows
If i2 = c Then
i1 = i1 + 1
End If
Else
s = wksAufruf.Cells(i1, i2).Value
End If
wksActive.Cells(r1, i2) = s
Next i2
r1 = r1 + 1
Next i1

wkbAufruf.Close False 'close without saving

ActiveWorkbook.Sheets(2).Delete 'close cheets 2 and 3 of the newly created worksheet
ActiveWorkbook.Sheets(2).Delete

'delete upper row
For i1 = 1 To head - 1
Rows("1").EntireRow.Delete
Next i1

'delete bottom row
r = wksActive.UsedRange.Rows.Count
For r1 = 1 To r
If wksActive.Cells(r1, 3).Value = "" Then
Exit For 'find row to delete
End If
Next r1

i1 = r1
For r1 = i1 To r
wksActive.Rows(i1).EntireRow.Delete
Next r1


For i2 = 1 To c 'delete empty columns
If wksActive.Cells(1, i2).Value = "" Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " _
Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Or wksActive.Cells(1, i2).Value = " " Then
wksActive.Columns(i2).EntireColumn.Delete
If i2 <= rel Then
rel = rel - 1
End If

If i2 = c Then
Exit For
End If

i2 = i2 - 1
c = c - 1
End If
Next i2

'released and received
For i2 = 1 To wksActive.UsedRange.Columns.Count
s = ""
If i2 > 1 And i2 < rel Then
s = "RECEIVED " & wksActive.Cells(1, i2)
ElseIf i2 >= rel And i2 < wksActive.UsedRange.Columns.Count Then
s = "RELEASED " & wksActive.Cells(1, i2)
Else
s = wksActive.Cells(1, i2)
End If
wksActive.Cells(1, i2) = s
Next i2

Modul2.ColumnManagement wksActive

Dim k As Integer
k = InStr(1, name, ".")
name = Left(name, k - 1)

ActiveWorkbook.SaveAs out & "FD_" & name & "." & filetype
ActiveWorkbook.Close

End Sub

Sub main()
DateiAufrufen
DateiErstellen
End Sub






excel vba excel-vba






share|improve this question









New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited yesterday









Pᴇʜ

18.3k42549




18.3k42549






New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









cynthia

1




1




New contributor




cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






cynthia is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • Where there is sheet(1) change that to 2 or 3 to do the respective sheets.
    – Luuklag
    yesterday










  • avoid too long lines. No one likes horizontal scrolling
    – phuclv
    yesterday


















  • Where there is sheet(1) change that to 2 or 3 to do the respective sheets.
    – Luuklag
    yesterday










  • avoid too long lines. No one likes horizontal scrolling
    – phuclv
    yesterday
















Where there is sheet(1) change that to 2 or 3 to do the respective sheets.
– Luuklag
yesterday




Where there is sheet(1) change that to 2 or 3 to do the respective sheets.
– Luuklag
yesterday












avoid too long lines. No one likes horizontal scrolling
– phuclv
yesterday




avoid too long lines. No one likes horizontal scrolling
– phuclv
yesterday

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






cynthia is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53183846%2frun-macro-on-2-or-3-pages%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








cynthia is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















cynthia is a new contributor. Be nice, and check out our Code of Conduct.













cynthia is a new contributor. Be nice, and check out our Code of Conduct.












cynthia is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53183846%2frun-macro-on-2-or-3-pages%23new-answer', 'question_page');
}
);

Post as a guest




















































































X,JZotmZ8 2OW1gH4,MbWOnB xTxHIV5O 7N32m5VrdjsYr,T7 cgD,pdXeFW
77HSylT7BJ7KZCZPd,Qf 2n 2pcrMedT4Gft4Ny9vb7ohljwKMl

Popular posts from this blog

横浜市

Rostock

Europa