Enter fixed data pattern bassed on user input

hugo15

New Member
Joined
Feb 18, 2010
Messages
23
I've been going round in circles with this for hours and have got no-where. Can anyone help? I 'm trying to get Excel to paste in a set pattern of data based on an input cell.

In row 1 I have months starting in cell B1. B1 = April 12, C1 = May 12, D1 = June 12, and so on

The user would enter the data in column A, starting in row 2

If the date in A2 = May 12 then Excel would enter 10 in cell C2, 20 in cell D2 and 30 in cell E2. If the date in A2 is changed to June 12, then the previous data would be cleared and Excel would enter 10 in E2, 20 in F2 and 30 in G2.

Date would be entered in A3, A4, A5 etc and I would want it to post the same fixed data depending on the date the user enters in teh relevant row.

I've tried IF statements and also some code but can't even get near it working. If anyone can help it would be greatly appreciated.
 
No need to apologise for being blunt Rick, I've leant my lesson! I'll try to explain what I'm trying to do more clearly.

In row 1 I have months starting in cell B1. B1 = April 12, C1 = May 12, D1 = June 12, and so on
A2 is where the user would input the start date.

What I want it to do is based on the start date, go to that month and enter a fixed pattern of data. The maximum number of data points would be 36.
For example if the user entered a start date of June 12, Excel would go to cell D2 and paste in the 36 data points into D2 and the next 35 cell to the right of it The values of the 36 data points would be fixed and could be typed into the spreadsheet as standing data or entered into the macro code.

Hope this is a little clearer.
 
Upvote 0

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Okay, I think I understand what you are looking for. See if this macro does what you want (adjust the comma delimited pattern that is assigned to the Pattern variable to suit your actual needs)...

Code:
Sub ApplyPatternFromDates()
  Dim X As Long, Z As Long, LastRow As Long, LastCol As Long
  Dim Pattern As String, PatArr As Variant, HeaderCell As Range
  Pattern = "10, 0, 0, 10, 0, 0, 30, 0, 0, 10, 10, 0, 0"
  PatArr = Split(Replace(Pattern, " ", ""), ",")
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
  For X = 2 To LastRow
    For Z = 2 To LastCol
      If Format(Cells(X, "A").Value, "mm yyyy") = Format(Cells(1, Z).Value, "mm yyyy") Then
        With Cells(X, Z).Resize(, UBound(PatArr))
          .Value = PatArr
          .Value = .Value
        End With
      End If
    Next
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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