Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Must add 1 to InputBox entry for code to work properly

Code is modified by OP from Claus' original.

Why must I add 1 to the Inputbox entries to return the proper "Week"?

Without the + 1, entries of 2 and 4 return Week1 to Week3.

https://www.dropbox.com/s/lnjqgmpnlc...ader.xlsm?dl=0

Howard

Sub Week_Reader_A_revised()
'/ by Claus @ MS Public (Modified by OP)

Dim fWeek As Long, lWeek As Long, lRow As Long, i As Long
Dim myArr As Variant
Dim f As Range, l As Range, myRng As Range, wkRng As Range

fWeek = Application.InputBox("Enter the STARTING WEEK to search for", "Start Weeknumber", Type:=1) + 1
If fWeek = False Then Exit Sub

lWeek = Application.InputBox("Enter the ENDING WEEK to search for", "Last Weeknumber", Type:=1) + 1
If lWeek = False Then Exit Sub

Sheets("Master").UsedRange.ClearContents

myArr = Array("Bodypump", "Bodystep-step", "Y-Blitz", "Y-Chisel", "Y-Cycle", "Zumba")

Application.ScreenUpdating = False

For i = 0 To UBound(myArr)
Set myRng = Nothing
With Sheets(myArr(i))

Set f = .Range("A2:A100").Find(fWeek, LookIn:=xlValues, lookat:=xlPart)
Set l = .Range("A2:A100").Find(lWeek, LookIn:=xlValues, lookat:=xlPart)
If Not f Is Nothing Then
lRow = Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row

If lRow = 1 Then
Set wkRng = .Range(fWeek & ":" & lWeek)
Set myRng = Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Range("A1")

Else

Set wkRng = .Range(fWeek & ":" & lWeek)
Set myRng = Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Cells(lRow + 2, 1)

End If
End If
End With
Next

Sheets("Master").Columns("A:Z").AutoFit
Sheets("Master").Rows("1:200").AutoFit
Application.ScreenUpdating = True
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Must add 1 to InputBox entry for code to work properly

Hi Howard,

Am Wed, 25 Mar 2015 22:51:23 -0700 (PDT) schrieb L. Howard:

If lRow = 1 Then
Set wkRng = .Range(fWeek & ":" & lWeek)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Set myRng = Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Range("A1")

Else

Set wkRng = .Range(fWeek & ":" & lWeek)

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Set myRng = Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Cells(lRow + 2, 1)

End If
End If

^
the mistake is in the lines above.
Change them to:

If lRow = 1 Then
Set wkRng = .Rows(f.Row & ":" & l.Row)
wkRng.Copy Sheets("Master").Range("A1")
Else
Set wkRng = .Rows(f.Row & ":" & l.Row)
wkRng.Copy Sheets("Master").Cells(lRow + 2, 1)
End If
End If



Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Must add 1 to InputBox entry for code to work properly

Hi Howard,

Am Thu, 26 Mar 2015 07:55:00 +0100 schrieb Claus Busch:

If lRow = 1 Then
Set wkRng = .Rows(f.Row & ":" & l.Row)
wkRng.Copy Sheets("Master").Range("A1")
Else
Set wkRng = .Rows(f.Row & ":" & l.Row)
wkRng.Copy Sheets("Master").Cells(lRow + 2, 1)
End If


sorry, forgot the headers:

If lRow = 1 Then
Set wkRng = .Rows(f.Row & ":" & l.Row)
Set myRng = Application.Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Range("A1")
Else
Set wkRng = .Rows(f.Row & ":" & l.Row)
Set myRng = Application.Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Cells(lRow + 2, 1)
End If


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 852
Default Must add 1 to InputBox entry for code to work properly

On Wednesday, March 25, 2015 at 11:59:03 PM UTC-7, Claus Busch wrote:
Hi Howard,

Am Thu, 26 Mar 2015 07:55:00 +0100 schrieb Claus Busch:

If lRow = 1 Then
Set wkRng = .Rows(f.Row & ":" & l.Row)
wkRng.Copy Sheets("Master").Range("A1")
Else
Set wkRng = .Rows(f.Row & ":" & l.Row)
wkRng.Copy Sheets("Master").Cells(lRow + 2, 1)
End If


sorry, forgot the headers:

If lRow = 1 Then
Set wkRng = .Rows(f.Row & ":" & l.Row)
Set myRng = Application.Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Range("A1")
Else
Set wkRng = .Rows(f.Row & ":" & l.Row)
Set myRng = Application.Union(.Rows(1), wkRng)
myRng.Copy Sheets("Master").Cells(lRow + 2, 1)
End If


Regards
Claus B.



Oh boy, I would have never sorted that out.

Works mighty fine.

Thanks again.

Howard
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
Code to save Word-document do not work properly jkrons Excel Programming 3 May 6th 10 08:44 PM
How to use InputBox for passphrase entry? Joe User[_2_] Excel Programming 4 February 8th 10 03:36 PM
Validate InputBox entry davidm Excel Programming 0 August 31st 05 03:03 AM
Msgbox if Inputbox entry contains character Steph[_3_] Excel Programming 1 June 23rd 05 06:02 PM
Can't get code to work properly. Please Help! sparky3883[_8_] Excel Programming 2 April 15th 04 01:55 PM


All times are GMT +1. The time now is 08:13 PM.

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

About Us

"It's about Microsoft Excel"