VBA select cells between two values

rifton

New Member
Joined
Apr 25, 2018
Messages
6
Dear,

I am a new poster. I found lots of information here about many ways to program and I am working as of today on an import file.
What it means is that there is a file in which information is held and it needs to go in a specific format in another file to be imported in a CRM.


What I have as of today is this:

Code:
Dim constFixWeek As String
Dim rngRange As Range
Dim strPlanning As String
 
Dim wrkRollout As Workbook
Set wrkRollout = Excel.ActiveWorkbook

Dim shtplanning As Worksheet
strPlanning = "Planning Materiel"
Set shtplanning = wrkRollout.Worksheets(strPlanning)

constFixWeek = "WEEK "

strSelectCell = constFixWeek & intWeek

Set rngRange = shtplanning.Cells.Find(What:=strSelectCell, _
                                            LookIn:=xlValues, _
                                            LookAt:=xlPart, _
                                            SearchOrder:=xlByRows, _
                                            SearchDirection:=xlNext, _
                                            MatchCase:=False)

If Not rngRange Is Nothing Then
        rngRange.Select
Else
        MsgBox "No match found."
End If

Now I'm stuck because I need to know how I can select a number of rows between 2 weeks.
it can be a variable amount of cells to be selected of course
[TABLE="width: 500"]
<tbody>[TR]
[TD]WEEK 19
[/TD]
[/TR]
[TR]
[TD]value to be selected
[/TD]
[/TR]
[TR]
[TD]value to be selected
[/TD]
[/TR]
[TR]
[TD]value to be selected
[/TD]
[/TR]
[TR]
[TD]WEEK 20
[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hey Steve059L

Sure, here's a snapshot of my data

[TABLE="class: grid, width: 100%"]
<tbody>[TR]
[TD]Branch number
[/TD]
[TD]Branch Name
[/TD]
[TD]screen
[/TD]
[TD]laptop
[/TD]
[TD]case
[/TD]
[TD]reader
[/TD]
[TD]cable
[/TD]
[/TR]
[TR]
[TD]WEEK 15
[/TD]
[TD][/TD]
[TD]1000022274
[/TD]
[TD]1000021969
[/TD]
[TD]1000020798
[/TD]
[TD]1000019625
[/TD]
[TD]1000007442
[/TD]
[/TR]
[TR]
[TD]310061
[/TD]
[TD]BRANCH 1
[/TD]
[TD="align: right"]15
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310114
[/TD]
[TD]BRANCH 2
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]WEEK 16
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310002
[/TD]
[TD]BRANCH 4
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]WEEK 17
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310906
[/TD]
[TD]BRANCH 6
[/TD]
[TD="align: right"]6
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310031
[/TD]
[TD]BRANCH 7
[/TD]
[TD="align: right"]7
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]WEEK 18
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310023
[/TD]
[TD]BRANCH 9
[/TD]
[TD="align: right"]14
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]3
[/TD]
[TD="align: right"]3
[/TD]
[/TR]
[TR]
[TD]310077
[/TD]
[TD]BRANCH 10
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]1
[/TD]
[/TR]
[TR]
[TD]310103
[/TD]
[TD]BRANCH 11
[/TD]
[TD="align: right"]14
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]2
[/TD]
[/TR]
[TR]
[TD]WEEK 19
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310000
[/TD]
[TD]BRANCH 13
[/TD]
[TD="align: right"]19
[/TD]
[TD="align: right"]19
[/TD]
[TD="align: right"]19
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310111
[/TD]
[TD]BRANCH 14
[/TD]
[TD="align: right"]35
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"]8
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310017
[/TD]
[TD]BRANCH 15
[/TD]
[TD="align: right"]6
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"]2
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310067
[/TD]
[TD]BRANCH 16
[/TD]
[TD="align: right"]5
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"]1
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310024
[/TD]
[TD]BRANCH 17
[/TD]
[TD="align: right"]6
[/TD]
[TD="align: right"]4
[/TD]
[TD="align: right"]4
[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]

At the end of this project I will need to export this data into a very specific format for the CMS I'm using to order a certain number of article numbers(row2,column3)

export example of week 19 done manually(will be saved in .csv afterwards)

[TABLE="class: grid, width: 100%"]
<tbody>[TR]
[TD]Branch Number[/TD]
[TD]Branch Name[/TD]
[TD]fixed value[/TD]
[TD]fixed value[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]fixed value[/TD]
[TD="colspan: 2"]fixed value[/TD]
[TD="colspan: 2"]fixed value[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]fixed value[/TD]
[TD]article number[/TD]
[TD][/TD]
[TD]Qty[/TD]
[TD]Qty[/TD]
[TD]fixed value[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000022274[/TD]
[TD][/TD]
[TD]19[/TD]
[TD]19[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000021969[/TD]
[TD][/TD]
[TD="align: right"]19[/TD]
[TD="align: right"]19[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000020798[/TD]
[TD][/TD]
[TD="align: right"]19[/TD]
[TD="align: right"]19[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000019625[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000007442[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD]WO[/TD]
[/TR]
</tbody><colgroup><col><col><col span="5"><col span="18"><col><col span="4"></colgroup>[/TABLE]

As you can see lots of rows need to be empty.

What I thus need it to do is
- find branch number
- create as many branch numbers as articles even 0 Qty values(I used transpose manually)
- do all this per selected week

don't hesitate if you have questions
 
Upvote 0
This is the full code I have so far:
Code:
Public Sub creation_import_materiel()


Dim wrkRollout, wrkCSV As Workbook
Dim strFullWeekName As String
Dim Target As Range

strFullWeekName = strSelectCells()

'Selection
Dim constFixWeek As String
Dim rngRange As Range
Dim strPlanning As String
Dim strSelectCells As String



Dim wrkRollout As Workbook
Set wrkRollout = Excel.ActiveWorkbook


Dim shtplanning As Worksheet
strPlanning = "Planning Materiel"
Set shtplanning = wrkRollout.Worksheets(strPlanning)

constFixWeek = "WEEK "

strSelectCell = constFixWeek & intWeek 'function that asks the week number


Set rngRange = shtplanning.Cells.Find(What:=strSelectCell, _
                                            LookIn:=xlValues, _
                                            LookAt:=xlPart, _
                                            SearchOrder:=xlByRows, _
                                            SearchDirection:=xlNext, _
                                            MatchCase:=False)
                                        

If Not rngRange Is Nothing Then
          rngRange.Select
          ActiveCell.Offset(1, 0).Range("A1:A5").Select
          
Else
        MsgBox "No match found."
End If

End Sub
 
Upvote 0
Hey Steve059L

Sure, here's a snapshot of my data

[TABLE="class: grid, width: 100%"]
<tbody>[TR]
[TD]Branch number[/TD]
[TD]Branch Name[/TD]
[TD]screen[/TD]
[TD]laptop[/TD]
[TD]case[/TD]
[TD]reader[/TD]
[TD]cable[/TD]
[/TR]
[TR]
[TD]WEEK 15[/TD]
[TD][/TD]
[TD]1000022274[/TD]
[TD]1000021969[/TD]
[TD]1000020798[/TD]
[TD]1000019625[/TD]
[TD]1000007442[/TD]
[/TR]
[TR]
[TD]310061[/TD]
[TD]BRANCH 1[/TD]
[TD="align: right"]15[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310114[/TD]
[TD]BRANCH 2[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]WEEK 16[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310002[/TD]
[TD]BRANCH 4[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]WEEK 17[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310906[/TD]
[TD]BRANCH 6[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310031[/TD]
[TD]BRANCH 7[/TD]
[TD="align: right"]7[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]WEEK 18[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310023[/TD]
[TD]BRANCH 9[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[TD="align: right"]3[/TD]
[/TR]
[TR]
[TD]310077[/TD]
[TD]BRANCH 10[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[/TR]
[TR]
[TD]310103[/TD]
[TD]BRANCH 11[/TD]
[TD="align: right"]14[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[/TR]
[TR]
[TD]WEEK 19[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]310000[/TD]
[TD]BRANCH 13[/TD]
[TD="align: right"]19[/TD]
[TD="align: right"]19[/TD]
[TD="align: right"]19[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310111[/TD]
[TD]BRANCH 14[/TD]
[TD="align: right"]35[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"]8[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310017[/TD]
[TD]BRANCH 15[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310067[/TD]
[TD]BRANCH 16[/TD]
[TD="align: right"]5[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD]310024[/TD]
[TD]BRANCH 17[/TD]
[TD="align: right"]6[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]

At the end of this project I will need to export this data into a very specific format for the CMS I'm using to order a certain number of article numbers(row2,column3)

export example of week 19 done manually(will be saved in .csv afterwards)

[TABLE="class: grid, width: 100%"]
<tbody>[TR]
[TD]Branch Number[/TD]
[TD]Branch Name[/TD]
[TD]fixed value[/TD]
[TD]fixed value[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]fixed value[/TD]
[TD="colspan: 2"]fixed value[/TD]
[TD="colspan: 2"]fixed value[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]fixed value[/TD]
[TD]article number[/TD]
[TD][/TD]
[TD]Qty[/TD]
[TD]Qty[/TD]
[TD]fixed value[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000022274[/TD]
[TD][/TD]
[TD]19[/TD]
[TD]19[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000021969[/TD]
[TD][/TD]
[TD="align: right"]19[/TD]
[TD="align: right"]19[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000020798[/TD]
[TD][/TD]
[TD="align: right"]19[/TD]
[TD="align: right"]19[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000019625[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD]WO[/TD]
[/TR]
[TR]
[TD="align: right"]310000[/TD]
[TD]BRANCH 13[/TD]
[TD]TMINPRM[/TD]
[TD="align: right"]93[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]RQT[/TD]
[TD][/TD]
[TD]ATT[/TD]
[TD][/TD]
[TD="align: right"]3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1000007442[/TD]
[TD][/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD]WO[/TD]
[/TR]
</tbody>[/TABLE]

As you can see lots of rows need to be empty.

What I thus need it to do is
- find branch number
- create as many branch numbers as articles even 0 Qty values(I used transpose manually)
- do all this per selected week

don't hesitate if you have questions

Where are you getting the extra information from column C onwards?

As far as I can tell, you're only copying Branch Number & Branch Name, is this correct?

Are you trying to only pull it in one week periods? E.G week 19 - 20, or would you want to extend it to week 19 - 26 etc.
 
Upvote 0
The first table is done automatically with formula's based on an export from the CRM.

For the 2nd table, I'm entering
-Branch Number,
-Branch Name comes from a VLOOKUP
-the fixed value fields, well, they never change but have to be imported to the CRM(special codes)

I transpose
- the article number from the 1st table(always 15 values so far)
- Qty
- Qty is simple =AC2 in this example

So the Macro will get the week number, take the first value under it and make 15lines according to this structure,
then continue to do so until it finds the next week and I'll probably make it ask (later on)if you want to stop or go on with following week.
 
Upvote 0
Anyone knows how I can proceed.

I tried with the following code to go row by row, but it just goes on to an infinite loop
Code:
Do Until ActiveCell.Value2 = Left(ActiveCell.Value2, 1) = "W"
i = i + 1
rngRange.Offset(i, 0).Select
Debug.Print Left(strSelectCell, 1)

Loop
 
Upvote 0
My understanding is just that if you want to select the cells between "Week 19" & "Week 20".

Is this correct? If so, this would do it.

Code:
Sub Test()

WeekStr = "Week "
BeginWeek = InputBox("Please enter your starting week number.") '' E.G. 19 = Week 19
EndWeek = InputBox("Please enter your ending week number.") '' E.G. 20 = Week 20


Set BeginRng = ActiveSheet.Cells.Find(What:=WeekStr & BeginWeek, _
                                        LookIn:=xlValues, _
                                        Lookat:=xlPart, _
                                        SearchOrder:=xlByRows, _
                                        SearchDirection:=xlNext, _
                                        MatchCase:=False)
    
Set EndRng = ActiveSheet.Cells.Find(What:=WeekStr & EndWeek, _
                                        LookIn:=xlValues, _
                                        Lookat:=xlPart, _
                                        SearchOrder:=xlByRows, _
                                        SearchDirection:=xlNext, _
                                        MatchCase:=False)


If BeginRng Is Nothing Then
    MsgBox "No match found." & vbNewLine & "Please enter a valid starting week number."
ElseIf EndRng Is Nothing Then
    MsgBox "No match found." & vbNewLine & "Please enter a valid ending week number."
Else
    ActiveSheet.Range(Cells(BeginRng.Row + 1, 1), Cells(EndRng.Row - 1, 1)).Select
End If


End Sub

This will select between week 19 and week 20 if you input 19 in the first inputbox and 20 in the second.

[TABLE="width: 64"]
<colgroup><col width="64" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64"]Week 19[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Week 20[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Values[/TD]
[/TR]
[TR]
[TD]Week 21[/TD]
[/TR]
</tbody>[/TABLE]

Does this work for you?
 
Upvote 0
Great!
That works.

I've changed Endweek = Beginweek +1 as it's always week+1

Now I can continue my code with copy and paste fun(yeey) and rearranging the necessary data into a CSV.

Great many thanks.

It's really weird to say thanks Lewzerrrr:laugh:

 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top