• Privacywetgeving
    Het is bij Helpmij.nl niet toegestaan om persoonsgegevens in een voorbeeld te plaatsen. Alle voorbeelden die persoonsgegevens bevatten zullen zonder opgaaf van reden verwijderd worden. In de vraag zal specifiek vermeld moeten worden dat het om fictieve namen gaat.

Cel zoeken met VBA functie FIND a.h.v. datum

Status
Niet open voor verdere reacties.
Bedankt! Maar ik wil de cel geen naam geven, ik wil weten welk celnummer dit is (bijv. A3) om daarna een naam te definiëren als volgt:

Code:
Sub Test()

With Sheets("Stroomverbruik")
begindatum = Application.InputBox("title", "title2", FormatDateTime(Date, vbShortDate), Type:=1)
  If begindatum Then
   bdatum = Application.Match(CLng(begindatum), .Columns(1), 0)
   If IsNumeric(bdatum) Then .Cells(bdatum, 1).Name = "BEGIN" Else MsgBox "Begindatum niet gevonden in tabel."
  End If
End With

With Sheets("Stroomverbruik")
einddatum = Application.InputBox("title", "title2", FormatDateTime(Date, vbShortDate), Type:=1)
  If einddatum Then
   edatum = Application.Match(CLng(einddatum), .Columns(1), 0)
   If IsNumeric(bdatum) Then .Cells(edatum, 1).Name = "EIND" Else MsgBox "Einddatum niet gevonden in tabel."
  End If
End With


ActiveWorkbook.Names.Add Name:="Grafiekstroom_data", RefersTo:="BEGIN:EIND"

     
End Sub

Als ik de code zoals hierboven gebruik, komt er in de naamsdefinitie "Begin" en "Eind" te staan i.p.v. celnummer.
 
Bv.

Code:
Sub Test()
With Sheets("Stroomverbruik")
begindatum = Application.InputBox("title", "title2", FormatDateTime(Date, vbShortDate), Type:=1)
  If begindatum Then
   bdatum = Application.Match(CLng(begindatum), .Columns(1), 0)
   If IsNumeric(bdatum) Then BEGIN = .Cells(bdatum, 1).Address Else MsgBox "Begindatum niet gevonden in tabel."
  End If
einddatum = Application.InputBox("title", "title2", FormatDateTime(Date, vbShortDate), Type:=1)
  If einddatum Then
   edatum = Application.Match(CLng(einddatum), .Columns(1), 0)
   If IsNumeric(edatum) Then EIND = .Cells(edatum, 1).Address Else MsgBox "Einddatum niet gevonden in tabel."
  End If
 ThisWorkbook.Names.Add Name:="Grafiekstroom_data", RefersTo:=.Range(BEGIN & ":" & EIND)
End With
End Sub
Of:
Code:
.Range(BEGIN & ":" & EIND).Name = "Grafiekstroom_data"

Kleine aanpassing als je een van twee toch annuleert.
Code:
Sub Test()
With Sheets("Stroomverbruik")
begindatum = Application.InputBox("title", "title2", FormatDateTime(Date, vbShortDate), Type:=1)
  If begindatum Then
   bdatum = Application.Match(CLng(begindatum), .Columns(1), 0)
   If IsNumeric(bdatum) Then BEGIN = .Cells(bdatum, 1).Address Else MsgBox "Begindatum niet gevonden in tabel."
 einddatum = Application.InputBox("title", "title2", FormatDateTime(Date, vbShortDate), Type:=1)
  If einddatum Then
   edatum = Application.Match(CLng(einddatum), .Columns(1), 0)
   If IsNumeric(edatum) Then EIND = .Cells(edatum, 1).Address Else MsgBox "Einddatum niet gevonden in tabel."
  End If
  If Not IsEmpty(BEGIN) And Not IsEmpty(EIND) Then .Range(BEGIN & ":" & EIND).Name = "Grafiekstroom_data"
 End If
End With
End Sub
 
Laatst bewerkt:
Dit is geweldig. Hier kom ik veel verder mee, nu gaat het wel lukken. Hartelijk dank voor de geweldige hulp!
 
Mooi zo, nog een andere methode.
Code:
Sub Test()
Dim BEGIN As String, EIND As String
With Sheets("Stroomverbruik")
sv = Array(Application.InputBox("titel", "Begin", , , , , , 1), Application.InputBox("titel", "Eind", , , , , , 1))
  bdatum = Application.Match(CLng(sv(0)), .Columns(1), 0)
  edatum = Application.Match(CLng(sv(1)), .Columns(1), 0)
  If IsNumeric(bdatum) And IsNumeric(edatum) Then
   BEGIN = .Cells(bdatum, 1).Address
   EIND = .Cells(edatum, 1).Address
   .Range(BEGIN & ":" & EIND).Name = "Grafiekstroom_data"
  End If
End With
End Sub
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan